From bddc4ac9b3528a0fe359d51034c9b4e020561e19 Mon Sep 17 00:00:00 2001 From: bigeagle Date: Sun, 1 Dec 2013 13:30:09 +0800 Subject: [PATCH] more debugging --- README.md | 15 +++++++-------- hop/client.go | 6 ++++-- hop/config.go | 1 + hop/server.go | 12 +++++++----- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index cb54fc0..07acef4 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ So I'm going to implement a VPN with these features: 1. Pre-shared key based authentication, randomly generated key for encryption. NO SSL, maybe a reinvented SSL :). 2. "Frequency hopping"-like port and protocol hopping, both handshake and packet transmission will be acctually done in random port and protocol. -3. Flow obfuscation to hide HTTP characters. +3. Traffic shaping to hide protocol's statistical properties. Implemention ------- @@ -37,13 +37,12 @@ You can get updated release from https://github.com/bigeagle/gohop/releases , go ### Build and Install -There's no prebuilt binary relase yet, u need to compile it yourself. Go 1.1 enviroment is needed, google is your friend. - First get dependency libraries and gohop source code. ``` go get github.com/bigeagle/go-logging go get github.com/bigeagle/water +go get code.google.com/p/gcfg go get github.com/bigeagle/gohop ``` @@ -55,21 +54,21 @@ go install github.com/bigeagle/gohop ### Config and Run -on the server, if u are using it for anti-GFW internet access, ip forwarding is needed: +On the server, if u are using it for anti-GFW internet access, ip forwarding is needed: ``` sysctl net.ipv4.ip_forward=1 iptables -t nat -A POSTROUTING -j MASQUERADE ``` -edit `server.json` as your server's config file, **currently u need to set ip address manually**. Run +edit `server.ini` as your server's config file. Run ``` -gohop -server server.json +gohop server.ini ``` -at client side, edit `client.json` as your config file, custom routes is supported so that in-china network packets will not go through gohop. And again, **u need to set ip address manually**. Run +at client side, edit `client.ini` as your config file, custom routes is supported so that in-china network packets will not go through gohop. Run ``` -gohop -client client.json +gohop client.ini ``` wait until u see `Connection Initialized`, pay attention to your DNS config, if u are using a Chinese DNS server, u're still unable to access blocked websites. diff --git a/hop/client.go b/hop/client.go index 3e36ce6..ab382e3 100644 --- a/hop/client.go +++ b/hop/client.go @@ -72,7 +72,7 @@ type HopClient struct { func NewClient(cfg HopClientConfig) error { var err error - logger.Debug("%v", cfg) + // logger.Debug("%v", cfg) cipher, err = newHopCipher([]byte(cfg.Key)) if err != nil { return err @@ -253,8 +253,9 @@ func (clt *HopClient) handleUDP(server string) { buf := make([]byte, IFACE_BUFSIZE) for { + logger.Debug("waiting for udp packet") n, err := udpConn.Read(buf) - // logger.Debug("New UDP Packet, len: %d", n) + logger.Debug("New UDP Packet, len: %d", n) if err != nil { logger.Error(err.Error()) return @@ -262,6 +263,7 @@ func (clt *HopClient) handleUDP(server string) { hp, err := unpackHopPacket(buf[:n]) if err != nil { + logger.Debug("Error depacketing") continue } if handle_func, ok := pktHandle[hp.Flag]; ok { diff --git a/hop/config.go b/hop/config.go index ceefd6b..04415d5 100644 --- a/hop/config.go +++ b/hop/config.go @@ -204,6 +204,7 @@ func serverParseConfig(cfgFile string) (*hopServerConfig, error) { type HopServerConfig struct { HopStart int HopEnd int + ListenAddr string Addr string MTU int Key string diff --git a/hop/server.go b/hop/server.go index 7cda8b7..a20565c 100644 --- a/hop/server.go +++ b/hop/server.go @@ -122,7 +122,7 @@ func NewServer(cfg HopServerConfig) error { // serve for multiple ports for idx, port := 0, cfg.HopStart; port <= cfg.HopEnd; port++ { - go hopServer.listenAndServe(fmt.Sprintf("%d", port), idx) + go hopServer.listenAndServe(cfg.ListenAddr, fmt.Sprintf("%d", port), idx) idx++ } @@ -158,8 +158,8 @@ func NewServer(cfg HopServerConfig) error { } -func (srv *HopServer) listenAndServe(port string, idx int) { - port = ":" + port +func (srv *HopServer) listenAndServe(addr string, port string, idx int) { + port = addr + ":" + port udpAddr, err := net.ResolveUDPAddr("udp", port) if err != nil { logger.Error("Invalid port: %s", port) @@ -262,10 +262,12 @@ func (srv *HopServer) toClient(peer *HopPeer, flag byte, payload []byte, noise b hp.Flag = flag hp.payload = payload - // logger.Debug("Peer: %v", hpeer) if addr, idx, ok := peer.addr(); ok { + logger.Debug("peer: %v", addr) upacket := &udpPacket{addr, hp.Pack(), idx} srv.toNet[idx] <- upacket + } else { + logger.Debug("peer not found") } } @@ -297,7 +299,7 @@ func (srv *HopServer) bufferToClient(peer *HopPeer, buf []byte) { func (srv *HopServer) handleKnock(u *udpPacket, hp *HopPacket) { sid := uint64(binary.BigEndian.Uint32(hp.payload[:4])) - // logger.Debug("port knock from client %v, sid: %d", u.addr, sid) + logger.Debug("port knock from client %v, sid: %d", u.addr, sid) sid = (sid << 32) & uint64(0xFFFFFFFF00000000) hpeer, ok := srv.peers[sid]