diff --git a/cli/brook/main.go b/cli/brook/main.go index c83755e2..6e407019 100644 --- a/cli/brook/main.go +++ b/cli/brook/main.go @@ -38,6 +38,7 @@ import ( "github.com/txthinking/brook" "github.com/txthinking/brook/plugins/block" + "github.com/txthinking/brook/plugins/dialwithip" "github.com/txthinking/brook/plugins/logger" "github.com/txthinking/brook/plugins/pprof" "github.com/txthinking/brook/plugins/socks5dial" @@ -76,6 +77,36 @@ func main() { Name: "tag", Usage: "Tag can be used to the process, will be append into log, such as: 'key1:value1'", }, + &cli.StringFlag{ + Name: "dialWithIP4", + Usage: "When the current machine establishes a network connection to the outside IPv4, both TCP and UDP, it is used to specify the IPv4 used", + }, + &cli.StringFlag{ + Name: "dialWithIP6", + Usage: "When the current machine establishes a network connection to the outside IPv6, both TCP and UDP, it is used to specify the IPv6 used", + }, + &cli.StringFlag{ + Name: "dialWithSocks5", + Usage: "When the current machine establishes a network connection to the outside, both TCP and UDP, with your socks5 proxy, such as 127.0.0.1:1081", + }, + &cli.StringFlag{ + Name: "dialWithSocks5Username", + Usage: "If there is", + }, + &cli.StringFlag{ + Name: "dialWithSocks5Password", + Usage: "If there is", + }, + &cli.IntFlag{ + Name: "dialWithSocks5TCPTimeout", + Value: 0, + Usage: "time (s)", + }, + &cli.IntFlag{ + Name: "dialWithSocks5UDPTimeout", + Value: 60, + Usage: "time (s)", + }, } app.Before = func(c *cli.Context) error { if c.String("pprof") != "" { @@ -118,6 +149,20 @@ func main() { f() } } + if c.String("dialWithIP4") != "" || c.String("dialWithIP6") != "" { + p, err := dialwithip.NewDialWithIP(c.String("dialWithIP4"), c.String("dialWithIP6")) + if err != nil { + return err + } + p.TouchBrook() + } + if c.String("dialWithSocks5") != "" { + p, err := socks5dial.NewSocks5Dial(c.String("dialWithSocks5"), c.String("dialWithSocks5Username"), c.String("dialWithSocks5Password"), c.Int("dialWithSocks5TCPTimeout"), c.Int("dialWithSocks5UDPTimeout")) + if err != nil { + return err + } + p.TouchBrook() + } return nil } app.Commands = []*cli.Command{ @@ -171,18 +216,6 @@ func main() { Name: "updateListInterval", Usage: "Update list interval, second. default 0, only read one time on start", }, - &cli.StringFlag{ - Name: "toSocks5", - Usage: "Forward to socks5 server, requires your socks5 supports standard socks5 TCP and UDP, such as 1.2.3.4:1080", - }, - &cli.StringFlag{ - Name: "toSocks5Username", - Usage: "Forward to socks5 server, username", - }, - &cli.StringFlag{ - Name: "toSocks5Password", - Usage: "Forward to socks5 server, password", - }, }, Action: func(c *cli.Context) error { if c.String("listen") == "" || c.String("password") == "" { @@ -220,13 +253,6 @@ func main() { if err != nil { return err } - if c.String("toSocks5") != "" { - p, err := socks5dial.NewSocks5Dial(c.String("toSocks5"), c.String("toSocks5Username"), c.String("toSocks5Password"), c.Int("tcpTimeout"), c.Int("udpTimeout")) - if err != nil { - return err - } - p.TouchBrook() - } g.Add(&runnergroup.Runner{ Start: func() error { return s.ListenAndServe() @@ -285,18 +311,6 @@ func main() { Value: 60, Usage: "time (s)", }, - &cli.StringFlag{ - Name: "dialWithSocks5", - Usage: "Dial with your socks5 proxy, such as 127.0.0.1:1081", - }, - &cli.StringFlag{ - Name: "dialWithSocks5Username", - Usage: "Optional", - }, - &cli.StringFlag{ - Name: "dialWithSocks5Password", - Usage: "Optional", - }, }, Action: func(c *cli.Context) error { if c.String("socks5") == "" || c.String("server") == "" || c.String("password") == "" { @@ -309,13 +323,6 @@ func main() { if h == "" && c.String("socks5ServerIP") == "" { return errors.New("socks5 server requires a clear IP for UDP, only port is not enough. You may use loopback IP or lan IP or other, we can not decide for you") } - if c.String("dialWithSocks5") != "" { - p, err := socks5dial.NewSocks5Dial(c.String("dialWithSocks5"), c.String("dialWithSocks5Username"), c.String("dialWithSocks5Password"), c.Int("tcpTimeout"), c.Int("udpTimeout")) - if err != nil { - return err - } - p.TouchBrook() - } var ip string if h != "" { ip = h @@ -418,18 +425,6 @@ func main() { Name: "updateListInterval", Usage: "Update list interval, second. default 0, only read one time on start", }, - &cli.StringFlag{ - Name: "toSocks5", - Usage: "Forward to socks5 server, requires your socks5 supports standard socks5 TCP and UDP, such as 1.2.3.4:1080", - }, - &cli.StringFlag{ - Name: "toSocks5Username", - Usage: "Forward to socks5 server, username", - }, - &cli.StringFlag{ - Name: "toSocks5Password", - Usage: "Forward to socks5 server, password", - }, }, Action: func(c *cli.Context) error { if c.String("listen") == "" || c.String("password") == "" { @@ -463,13 +458,6 @@ func main() { }) } } - if c.String("toSocks5") != "" { - p, err := socks5dial.NewSocks5Dial(c.String("toSocks5"), c.String("toSocks5Username"), c.String("toSocks5Password"), c.Int("tcpTimeout"), c.Int("udpTimeout")) - if err != nil { - return err - } - p.TouchBrook() - } s, err := brook.NewWSServer(c.String("listen"), c.String("password"), "", c.String("path"), c.Int("tcpTimeout"), c.Int("udpTimeout"), c.Bool("withoutBrookProtocol")) if err != nil { return err @@ -536,18 +524,6 @@ func main() { Value: 60, Usage: "time (s)", }, - &cli.StringFlag{ - Name: "dialWithSocks5", - Usage: "Dial with your socks5 proxy, such as 127.0.0.1:1081", - }, - &cli.StringFlag{ - Name: "dialWithSocks5Username", - Usage: "Optional", - }, - &cli.StringFlag{ - Name: "dialWithSocks5Password", - Usage: "Optional", - }, }, Action: func(c *cli.Context) error { if c.String("socks5") == "" || c.String("wsserver") == "" || c.String("password") == "" { @@ -560,13 +536,6 @@ func main() { if h == "" && c.String("socks5ServerIP") == "" { return errors.New("socks5 server requires a clear IP for UDP, only port is not enough. You may use loopback IP or lan IP or other, we can not decide for you") } - if c.String("dialWithSocks5") != "" { - p, err := socks5dial.NewSocks5Dial(c.String("dialWithSocks5"), c.String("dialWithSocks5Username"), c.String("dialWithSocks5Password"), c.Int("tcpTimeout"), c.Int("udpTimeout")) - if err != nil { - return err - } - p.TouchBrook() - } var ip string if h != "" { ip = h @@ -672,18 +641,6 @@ func main() { Name: "updateListInterval", Usage: "Update list interval, second. default 0, only read one time on start", }, - &cli.StringFlag{ - Name: "toSocks5", - Usage: "Forward to socks5 server, requires your socks5 supports standard socks5 TCP and UDP, such as 1.2.3.4:1080", - }, - &cli.StringFlag{ - Name: "toSocks5Username", - Usage: "Forward to socks5 server, username", - }, - &cli.StringFlag{ - Name: "toSocks5Password", - Usage: "Forward to socks5 server, password", - }, }, Action: func(c *cli.Context) error { if c.String("domainaddress") == "" || c.String("password") == "" { @@ -723,13 +680,6 @@ func main() { }) } } - if c.String("toSocks5") != "" { - p, err := socks5dial.NewSocks5Dial(c.String("toSocks5"), c.String("toSocks5Username"), c.String("toSocks5Password"), c.Int("tcpTimeout"), c.Int("udpTimeout")) - if err != nil { - return err - } - p.TouchBrook() - } h, p, err := net.SplitHostPort(c.String("domainaddress")) if err != nil { return err @@ -822,18 +772,6 @@ func main() { Value: 60, Usage: "time (s)", }, - &cli.StringFlag{ - Name: "dialWithSocks5", - Usage: "Dial with your socks5 proxy, such as 127.0.0.1:1081", - }, - &cli.StringFlag{ - Name: "dialWithSocks5Username", - Usage: "Optional", - }, - &cli.StringFlag{ - Name: "dialWithSocks5Password", - Usage: "Optional", - }, }, Action: func(c *cli.Context) error { if c.String("socks5") == "" || c.String("wssserver") == "" || c.String("password") == "" { @@ -846,13 +784,6 @@ func main() { if h == "" && c.String("socks5ServerIP") == "" { return errors.New("socks5 server requires a clear IP for UDP, only port is not enough. You may use loopback IP or lan IP or other, we can not decide for you") } - if c.String("dialWithSocks5") != "" { - p, err := socks5dial.NewSocks5Dial(c.String("dialWithSocks5"), c.String("dialWithSocks5Username"), c.String("dialWithSocks5Password"), c.Int("tcpTimeout"), c.Int("udpTimeout")) - if err != nil { - return err - } - p.TouchBrook() - } var ip string if h != "" { ip = h @@ -1042,7 +973,7 @@ func main() { }, &cli.Command{ Name: "quicclient", - Usage: "Run as brook quicclient, both TCP and UDP, to start a socks5 proxy, [src <-> socks5 <-> $ brook quicclient <-> $ brook quicserver <-> dst]", + Usage: "Run as brook quicclient, both TCP and UDP, to start a socks5 proxy, [src <-> socks5 <-> $ brook quicclient <-> $ brook quicserver <-> dst]. (Note that the global dial parameter is ignored now)", BashComplete: func(c *cli.Context) { l := c.Command.VisibleFlags() for _, v := range l { @@ -1064,9 +995,13 @@ func main() { Name: "address", Usage: "Specify address instead of resolving addresses from host, such as 1.2.3.4:443", }, + &cli.BoolFlag{ + Name: "insecure", + Usage: "Client do not verify the server's certificate chain and host name", + }, &cli.StringFlag{ Name: "ca", - Usage: "When server is brook wssserver, specify ca instead of insecure, such as /path/to/ca.pem", + Usage: "Specify ca instead of insecure, such as /path/to/ca.pem", }, &cli.BoolFlag{ Name: "withoutBrookProtocol", @@ -1121,6 +1056,9 @@ func main() { if c.String("address") != "" { s.ServerAddress = c.String("address") } + if c.Bool("insecure") { + s.TLSConfig.InsecureSkipVerify = true + } if c.String("ca") != "" { b, err := ioutil.ReadFile(c.String("ca")) if err != nil { @@ -1181,7 +1119,7 @@ func main() { &cli.StringFlag{ Name: "server", Aliases: []string{"s"}, - Usage: "brook server or brook wsserver or brook wssserver, like: 1.2.3.4:9999, ws://1.2.3.4:9999, wss://domain:443/ws, quic://domain.com:443", + Usage: "brook server or brook wsserver or brook wssserver or brook quicserver, like: 1.2.3.4:9999, ws://1.2.3.4:9999, wss://domain:443/ws, quic://domain.com:443", }, &cli.StringFlag{ Name: "password", @@ -1313,7 +1251,7 @@ func main() { &cli.StringFlag{ Name: "server", Aliases: []string{"s"}, - Usage: "brook server or brook wsserver or brook wssserver, like: 1.2.3.4:9999, ws://1.2.3.4:9999, wss://domain.com:443/ws, quic://domain.com:443", + Usage: "brook server or brook wsserver or brook wssserver or brook quicserver, like: 1.2.3.4:9999, ws://1.2.3.4:9999, wss://domain.com:443/ws, quic://domain.com:443", }, &cli.StringFlag{ Name: "password", @@ -1529,18 +1467,6 @@ func main() { Value: 60, Usage: "time (s)", }, - &cli.StringFlag{ - Name: "dialWithSocks5", - Usage: "Dial with your socks5 proxy, such as 127.0.0.1:1081", - }, - &cli.StringFlag{ - Name: "dialWithSocks5Username", - Usage: "Optional", - }, - &cli.StringFlag{ - Name: "dialWithSocks5Password", - Usage: "Optional", - }, }, Action: func(c *cli.Context) error { if c.String("webListen") != "" { @@ -1765,13 +1691,6 @@ func main() { } p.TouchBrook() } - if c.String("dialWithSocks5") != "" { - p, err := socks5dial.NewSocks5Dial(c.String("dialWithSocks5"), c.String("dialWithSocks5Username"), c.String("dialWithSocks5Password"), c.Int("tcpTimeout"), c.Int("udpTimeout")) - if err != nil { - return err - } - p.TouchBrook() - } kind := "server" if strings.HasPrefix(c.String("server"), "ws://") { kind = "wsserver" @@ -1984,18 +1903,6 @@ func main() { Value: 60, Usage: "time (s)", }, - &cli.StringFlag{ - Name: "dialWithSocks5", - Usage: "If you already have a socks5, such as 127.0.0.1:1081, and want [src <-> listen socks5 <-> $ brook connect <-> dialWithSocks5 <-> $ brook server/wsserver/wssserver <-> dst]", - }, - &cli.StringFlag{ - Name: "dialWithSocks5Username", - Usage: "Optional", - }, - &cli.StringFlag{ - Name: "dialWithSocks5Password", - Usage: "Optional", - }, }, Action: func(c *cli.Context) error { if c.String("link") == "" { @@ -2018,13 +1925,6 @@ func main() { if kind == "socks5" { return errors.New("Looks like you want create socks5 from a socks5, you may want $ brook socks5tohttp?") } - if c.String("dialWithSocks5") != "" { - p, err := socks5dial.NewSocks5Dial(c.String("dialWithSocks5"), c.String("dialWithSocks5Username"), c.String("dialWithSocks5Password"), c.Int("tcpTimeout"), c.Int("udpTimeout")) - if err != nil { - return err - } - p.TouchBrook() - } s, err := brook.NewBrookLink(c.String("link")) if err != nil { return err @@ -2193,20 +2093,20 @@ func main() { Flags: []cli.Flag{ &cli.StringFlag{ Name: "serverip", - Usage: "DHCP server IP, such as: 192.168.1.1", + Usage: "DHCP server IP, the IP of the this machine, you shoud set a static IP to this machine before doing this, such as: 192.168.1.10", }, &cli.StringFlag{ Name: "start", - Usage: "Start IP which you want to assign to clients, such as: 192.168.1.2", + Usage: "Start IP which you want to assign to clients, such as: 192.168.1.100", }, &cli.StringFlag{ Name: "netmask", - Usage: "Subnet netmask", + Usage: "Subnet netmask which you want to assign to clients", Value: "255.255.255.0", }, &cli.IntFlag{ Name: "count", - Usage: "IP range from the start", + Usage: "IP range from the start, which you want to assign to clients", Value: 100, }, &cli.StringFlag{ @@ -2478,7 +2378,7 @@ func main() { }, &cli.Command{ Name: "testbrook", - Usage: "Test UDP and TCP of brook server/wsserver/wssserver", + Usage: "Test UDP and TCP of brook server/wsserver/wssserver/quicserver. (Note that the global dial parameter is ignored now)", BashComplete: func(c *cli.Context) { l := c.Command.VisibleFlags() for _, v := range l { @@ -2526,6 +2426,7 @@ func main() { if err != nil { return } + // TODO append global dial options cmd = exec.Command(s, "connect", "--link", c.String("link"), "--socks5", c.String("socks5")) b, _ := cmd.CombinedOutput() err = errors.New(string(b)) diff --git a/dhcpserver.go b/dhcpserver.go index 1f02663b..18a17101 100644 --- a/dhcpserver.go +++ b/dhcpserver.go @@ -119,6 +119,7 @@ func (h *DHCPServer) ServeDHCP(p dhcp4.Packet, msgType dhcp4.MessageType, option return dhcp4.ReplyPacket(p, dhcp4.Offer, h.ServerIP, dhcp4.IPAdd(h.Start, i), 7*24*time.Hour, h.Options.SelectOrderOrAll(options[dhcp4.OptionParameterRequestList])) } } + Log(errors.New("DHCP server is full")) DHCPServerGate(msgType.String(), p, "", nil, errors.New("DHCP server is full")) return nil case dhcp4.Request: diff --git a/docs/example-zh.md b/docs/example-zh.md index 012a8744..37554670 100644 --- a/docs/example-zh.md +++ b/docs/example-zh.md @@ -188,19 +188,6 @@ brook wssserver --domainaddress domain.com:443 --password hello --cert /root/cer brook link --server wss://domain.com:443 --password hello --withoutBrookProtocol --address 1.2.3.4:443 --ca /root/ca.pem ``` -### brook server wsserver wssserver 服务端转发给另外的 socks5 server - -- --toSocks5 -- --toSocks5Username -- --toSocks5Password - -### brook server wsserver wssserver 在服务端屏蔽域名和 IP 列表 - -- --blockDomainList -- --blockCIDR4List -- --blockCIDR6List -- --updateListInterval - ### 运行 brook socks5, 一个独立的标准 socks5 server ``` diff --git a/docs/example.md b/docs/example.md index c56fdcf0..160e6d51 100644 --- a/docs/example.md +++ b/docs/example.md @@ -188,19 +188,6 @@ Get brook link brook link --server wss://domain.com:443 --password hello --withoutBrookProtocol --address 1.2.3.4:443 --ca /root/ca.pem ``` -### brook server wsserver wssserver forward to another socks5 server on server-side - -- --toSocks5 -- --toSocks5Username -- --toSocks5Password - -### brook server wsserver wssserver block domain and ip on server-side - -- --blockDomainList -- --blockCIDR4List -- --blockCIDR6List -- --updateListInterval - ### Run brook socks5, A stand-alone standard socks5 server ``` diff --git a/echoclient.go b/echoclient.go index 9ecf860b..c7819d6a 100644 --- a/echoclient.go +++ b/echoclient.go @@ -16,7 +16,6 @@ package brook import ( "fmt" - "net" ) func EchoClient(server string, times int) error { @@ -44,30 +43,26 @@ func EchoClient(server string, times int) error { } } - raddr, err := Resolve("udp", server) - if err != nil { - return err - } - c1, err := net.ListenUDP("udp", nil) + c1, err := DialUDP("udp", "", server) if err != nil { return err } defer c1.Close() for i := 0; i < times; i++ { - if _, err := c1.WriteToUDP([]byte(c1.LocalAddr().String()), raddr.(*net.UDPAddr)); err != nil { + if _, err := c1.Write([]byte(c1.LocalAddr().String())); err != nil { return err } - i, addr, err := c1.ReadFromUDP(b[:]) + i, err := c1.Read(b[:]) if err != nil { return err } if c1.LocalAddr().String() == string(b[:i]) { - fmt.Printf("UDP: src:%s -> dst:%s\n", c1.LocalAddr().String(), raddr.String()) - fmt.Printf("UDP: dst:%s <- src:%s\n", c1.LocalAddr().String(), addr.String()) + fmt.Printf("UDP: src:%s -> dst:%s\n", c1.LocalAddr().String(), c1.RemoteAddr().String()) + fmt.Printf("UDP: dst:%s <- src:%s\n", c1.LocalAddr().String(), c1.RemoteAddr().String()) } if c1.LocalAddr().String() != string(b[:i]) { - fmt.Printf("UDP: src:%s -> dst:proxy -> src:proxy -> dst:%s\n", c1.LocalAddr().String(), raddr.String()) - fmt.Printf("UDP: dst:%s <- src:proxy <- dst:%s <- src:%s\n", c1.LocalAddr().String(), string(b[:i]), addr.String()) + fmt.Printf("UDP: src:%s -> dst:proxy -> src:proxy -> dst:%s\n", c1.LocalAddr().String(), c1.RemoteAddr().String()) + fmt.Printf("UDP: dst:%s <- src:proxy <- dst:%s <- src:%s\n", c1.LocalAddr().String(), string(b[:i]), c1.RemoteAddr().String()) } } return nil diff --git a/ipk/data/usr/lib/lua/luci/view/brook.htm b/ipk/data/usr/lib/lua/luci/view/brook.htm index e4fcf07d..2970529c 100644 --- a/ipk/data/usr/lib/lua/luci/view/brook.htm +++ b/ipk/data/usr/lib/lua/luci/view/brook.htm @@ -6,7 +6,7 @@ a.innerText = "Back to OpenWrt"; document.body.appendChild(a); var e = document.createElement("iframe"); -e.src = `//${location.hostname}:9999`; +e.src = `http://${location.hostname}:9999`; e.style.border = 'none'; e.style.width = '100%'; e.style.height = '100vh'; diff --git a/plugins/dialwithip/dialwithip.go b/plugins/dialwithip/dialwithip.go new file mode 100644 index 00000000..b5796a42 --- /dev/null +++ b/plugins/dialwithip/dialwithip.go @@ -0,0 +1,98 @@ +// Copyright (c) 2016-present Cloud +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 3 of the GNU General Public +// License as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +package dialwithip + +import ( + "errors" + "net" + + "github.com/txthinking/brook" + "github.com/txthinking/socks5" +) + +type DialWithIP struct { + IP4 net.IP + IP6 net.IP +} + +func NewDialWithIP(ip4, ip6 string) (*DialWithIP, error) { + if ip4 != "" && (net.ParseIP(ip4) == nil || net.ParseIP(ip4).To4() == nil) { + return nil, errors.New("Invalid dial with IP") + } + if ip6 != "" && (net.ParseIP(ip6) == nil || net.ParseIP(ip6).To4() != nil) { + return nil, errors.New("Invalid dial with IP") + } + d := &DialWithIP{} + if ip4 != "" { + d.IP4 = net.ParseIP(ip4).To4() + } + if ip6 != "" { + d.IP6 = net.ParseIP(ip6).To16() + } + return d, nil +} + +func (p *DialWithIP) TouchBrook() { + brook.DialTCP = func(network string, laddr, raddr string) (net.Conn, error) { + var la, ra *net.TCPAddr + if laddr != "" { + var err error + la, err = net.ResolveTCPAddr(network, laddr) + if err != nil { + return nil, err + } + } + a, err := brook.Resolve(network, raddr) + if err != nil { + return nil, err + } + ra = a.(*net.TCPAddr) + if la == nil { + if ra.IP.To4() != nil && p.IP4 != nil { + la = &net.TCPAddr{IP: p.IP4} + } + if ra.IP.To4() == nil && p.IP6 != nil { + la = &net.TCPAddr{IP: p.IP6} + } + } + return net.DialTCP(network, la, ra) + } + brook.DialUDP = func(network string, laddr, raddr string) (net.Conn, error) { + var la, ra *net.UDPAddr + if laddr != "" { + var err error + la, err = net.ResolveUDPAddr(network, laddr) + if err != nil { + return nil, err + } + } + a, err := brook.Resolve(network, raddr) + if err != nil { + return nil, err + } + ra = a.(*net.UDPAddr) + if la == nil { + if ra.IP.To4() != nil && p.IP4 != nil { + la = &net.UDPAddr{IP: p.IP4} + } + if ra.IP.To4() == nil && p.IP6 != nil { + la = &net.UDPAddr{IP: p.IP6} + } + } + return net.DialUDP(network, la, ra) + } + socks5.DialTCP = brook.DialTCP + socks5.DialUDP = brook.DialUDP +} diff --git a/plugins/socks5dial/dial.go b/plugins/socks5dial/dial.go index 5a01507b..bbe2703f 100644 --- a/plugins/socks5dial/dial.go +++ b/plugins/socks5dial/dial.go @@ -37,9 +37,23 @@ func NewSocks5Dial(server, username, password string, tcptimeout, udptimeout int func (p *Socks5Dial) TouchBrook() { brook.DialTCP = func(network string, laddr, raddr string) (net.Conn, error) { - return p.s5c.DialWithLocalAddr("tcp", laddr, raddr, nil) + var fake net.Addr + if network == "tcp" { + fake = &net.TCPAddr{IP: net.IPv4zero} + } + if network == "udp" { + fake = &net.UDPAddr{IP: net.IPv4zero} + } + return p.s5c.DialWithLocalAddr("tcp", laddr, raddr, fake) } brook.DialUDP = func(network string, laddr, raddr string) (net.Conn, error) { - return p.s5c.DialWithLocalAddr("udp", laddr, raddr, nil) + var fake net.Addr + if network == "tcp" { + fake = &net.TCPAddr{IP: net.IPv4zero} + } + if network == "udp" { + fake = &net.UDPAddr{IP: net.IPv4zero} + } + return p.s5c.DialWithLocalAddr("udp", laddr, raddr, fake) } } diff --git a/test_test.go b/test_test.go index 13d2050a..ee3d6828 100644 --- a/test_test.go +++ b/test_test.go @@ -15,17 +15,8 @@ package brook import ( - "encoding/json" - "log" "testing" ) func TestTest(t *testing.T) { - m := make(map[string]int) - m["a"] = 1 - b, err := json.Marshal(m) - log.Println(string(b), err) - m["a"] = 2 - err = json.Unmarshal(b, &m) - log.Println(m, err) }