diff --git a/Makefile b/Makefile index 04e4ac9..d3fa2ee 100644 --- a/Makefile +++ b/Makefile @@ -10,4 +10,22 @@ doc: checklist find lib cmd -type d -exec $(HERE)/doc.sh {} \; checklist: - find . -name '*.go' -exec grep --color -C 1 -Hn 'panic("unimplemented")' {} \; \ No newline at end of file + find . -name '*.go' -exec grep --color -C 1 -Hn 'panic("unimplemented")' {} \; + +mobile: + go install golang.org/x/mobile/cmd/gomobile@latest + gomobile init + +bindSetupMobile: mobile + go get -u golang.org/x/mobile/bind + +mobileLibs: + gomobile bind -target=android ./lib/tcp/client + gomobile bind -target=android ./lib/tcp/server + gomobile bind -target=android ./lib/udp/client + gomobile bind -target=android ./lib/udp/server + gomobile bind -target=android ./lib/irc/client + gomobile bind -target=android ./lib/irc/server + gomobile bind -target=android ./lib/http/client + gomobile bind -target=android ./lib/http/server + gomobile bind -target=android ./lib/socks/client \ No newline at end of file diff --git a/lib/core/types.go b/lib/core/types.go index 3ffe27f..962a481 100644 --- a/lib/core/types.go +++ b/lib/core/types.go @@ -37,5 +37,5 @@ type I2PTunnel interface { // Get the tunnel's error message Error() error // Get the tunnel's local host:port - LocalAddress() (string, string, error) + LocalAddress() (string, error) } diff --git a/lib/http/client/httpclient.go b/lib/http/client/httpclient.go index d074bc9..157af29 100644 --- a/lib/http/client/httpclient.go +++ b/lib/http/client/httpclient.go @@ -23,6 +23,7 @@ Key features: **/ import ( + "net" "strconv" httpinspector "github.com/go-i2p/go-connfilter/http" @@ -67,8 +68,9 @@ func (h *HTTPClient) Error() error { } // Get the tunnel's local host:port -func (h *HTTPClient) LocalAddress() (string, string, error) { - return h.TunnelConfig.Interface, strconv.Itoa(h.TunnelConfig.Port), nil +func (h *HTTPClient) LocalAddress() (string, error) { + addr := net.JoinHostPort(h.TunnelConfig.Interface, strconv.Itoa(h.TunnelConfig.Port)) + return addr, nil } // Get the tunnel's name diff --git a/lib/http/server/httpserver.go b/lib/http/server/httpserver.go index 5cc191c..d40bffd 100644 --- a/lib/http/server/httpserver.go +++ b/lib/http/server/httpserver.go @@ -76,8 +76,9 @@ func (h *HTTPServer) Error() error { } // Get the tunnel's local host:port -func (h *HTTPServer) LocalAddress() (string, string, error) { - return h.TunnelConfig.Interface, strconv.Itoa(h.TunnelConfig.Port), nil +func (h *HTTPServer) LocalAddress() (string, error) { + addr := net.JoinHostPort(h.TunnelConfig.Interface, strconv.Itoa(h.TunnelConfig.Port)) + return addr, nil } // Get the tunnel's name diff --git a/lib/irc/client/client.go b/lib/irc/client/client.go index 264ce0e..7a4010b 100644 --- a/lib/irc/client/client.go +++ b/lib/irc/client/client.go @@ -13,6 +13,7 @@ The IRC Client implements a SOCKS-compatible proxy that enables local IRC client **/ import ( + "net" "strconv" ircinspector "github.com/go-i2p/go-connfilter/irc" @@ -60,8 +61,9 @@ func (i *IRCClient) Error() error { } // Get the tunnel's local host:port -func (i *IRCClient) LocalAddress() (string, string, error) { - return i.TunnelConfig.Interface, strconv.Itoa(i.TunnelConfig.Port), nil +func (i *IRCClient) LocalAddress() (string, error) { + addr := net.JoinHostPort(i.TunnelConfig.Interface, strconv.Itoa(i.TunnelConfig.Port)) + return addr, nil } // Get the tunnel's name diff --git a/lib/irc/server/server.go b/lib/irc/server/server.go index 9361f0c..c715fdc 100644 --- a/lib/irc/server/server.go +++ b/lib/irc/server/server.go @@ -66,8 +66,9 @@ func (i *IRCServer) Error() error { } // Get the tunnel's local host:port -func (i *IRCServer) LocalAddress() (string, string, error) { - return i.TunnelConfig.Interface, strconv.Itoa(i.TunnelConfig.Port), nil +func (i *IRCServer) LocalAddress() (string, error) { + addr := net.JoinHostPort(i.TunnelConfig.Interface, strconv.Itoa(i.TunnelConfig.Port)) + return addr, nil } // Get the tunnel's name diff --git a/lib/socks/client/socks.go b/lib/socks/client/socks.go index 638a4f8..9da5f42 100644 --- a/lib/socks/client/socks.go +++ b/lib/socks/client/socks.go @@ -92,8 +92,9 @@ func (s *SOCKS) Error() error { } // Get the tunnel's local host:port -func (s *SOCKS) LocalAddress() (string, string, error) { - return s.TunnelConfig.Interface, strconv.Itoa(s.TunnelConfig.Port), nil +func (s *SOCKS) LocalAddress() (string, error) { + addr := net.JoinHostPort(s.TunnelConfig.Interface, strconv.Itoa(s.TunnelConfig.Port)) + return addr, nil } // Get the tunnel's name diff --git a/lib/tcp/client/tcpclient.go b/lib/tcp/client/tcpclient.go index 529e57e..174c93f 100644 --- a/lib/tcp/client/tcpclient.go +++ b/lib/tcp/client/tcpclient.go @@ -69,8 +69,9 @@ func (t *TCPClient) Error() error { } // Get the tunnel's local host:port -func (t *TCPClient) LocalAddress() (string, string, error) { - return t.TunnelConfig.Interface, strconv.Itoa(t.TunnelConfig.Port), nil +func (t *TCPClient) LocalAddress() (string, error) { + addr := net.JoinHostPort(t.TunnelConfig.Interface, strconv.Itoa(t.TunnelConfig.Port)) + return addr, nil } // Get the tunnel's name diff --git a/lib/tcp/server/tcpserver.go b/lib/tcp/server/tcpserver.go index 1304a48..60bdba0 100644 --- a/lib/tcp/server/tcpserver.go +++ b/lib/tcp/server/tcpserver.go @@ -16,6 +16,7 @@ When an I2P peer connects to the tunnel's destination, the traffic flows: import ( "context" "net" + "strconv" "github.com/go-i2p/go-forward/config" "github.com/go-i2p/go-forward/stream" @@ -63,9 +64,9 @@ func (t *TCPServer) Error() error { } // Get the tunnel's local host:port -func (t *TCPServer) LocalAddress() (string, string, error) { - addr := t.Addr.String() - return net.SplitHostPort(addr) +func (t *TCPServer) LocalAddress() (string, error) { + addr := net.JoinHostPort(t.TunnelConfig.Interface, strconv.Itoa(t.TunnelConfig.Port)) + return addr, nil } // Get the tunnel's name diff --git a/lib/udp/client/udpclient.go b/lib/udp/client/udpclient.go index dd7b560..3e03257 100644 --- a/lib/udp/client/udpclient.go +++ b/lib/udp/client/udpclient.go @@ -71,8 +71,9 @@ func (u *UDPClient) Error() error { } // Get the tunnel's local host:port -func (u *UDPClient) LocalAddress() (string, string, error) { - return u.TunnelConfig.Interface, strconv.Itoa(u.TunnelConfig.Port), nil +func (u *UDPClient) LocalAddress() (string, error) { + addr := net.JoinHostPort(u.TunnelConfig.Interface, strconv.Itoa(u.TunnelConfig.Port)) + return addr, nil } // Get the tunnel's name diff --git a/lib/udp/server/udpserver.go b/lib/udp/server/udpserver.go index 4745942..9f71ba7 100644 --- a/lib/udp/server/udpserver.go +++ b/lib/udp/server/udpserver.go @@ -71,8 +71,9 @@ func (u *UDPServer) Error() error { } // Get the tunnel's local host:port -func (u *UDPServer) LocalAddress() (string, string, error) { - return u.TunnelConfig.Interface, strconv.Itoa(u.TunnelConfig.Port), nil +func (u *UDPServer) LocalAddress() (string, error) { + addr := net.JoinHostPort(u.TunnelConfig.Interface, strconv.Itoa(u.TunnelConfig.Port)) + return addr, nil } // Get the tunnel's name