diff --git a/src/yggdrasil/peer.go b/src/yggdrasil/peer.go index c122ab1c..7f1de6b2 100644 --- a/src/yggdrasil/peer.go +++ b/src/yggdrasil/peer.go @@ -223,8 +223,6 @@ func (p *peer) sendPacket(packet []byte) { func (p *peer) sendLinkPacket(packet []byte) { bs, nonce := boxSeal(&p.shared, packet, nil) linkPacket := wire_linkProtoTrafficPacket{ - //toKey: p.box, - //fromKey: p.core.boxPub, nonce: *nonce, payload: bs, } @@ -237,12 +235,6 @@ func (p *peer) handleLinkTraffic(bs []byte) { if !packet.decode(bs) { return } - //if packet.toKey != p.core.boxPub { - // return - //} - //if packet.fromKey != p.box { - // return - //} payload, isOK := boxOpen(&p.shared, packet.payload, &packet.nonce) if !isOK { return diff --git a/src/yggdrasil/router.go b/src/yggdrasil/router.go index 8bfa73b8..c25d64a7 100644 --- a/src/yggdrasil/router.go +++ b/src/yggdrasil/router.go @@ -295,9 +295,6 @@ func (r *router) handleDHTReq(bs []byte, fromKey *boxPubKey) { if !req.decode(bs) { return } - //if req.key != *fromKey { - // return - //} req.key = *fromKey r.core.dht.handleReq(&req) } @@ -307,9 +304,6 @@ func (r *router) handleDHTRes(bs []byte, fromKey *boxPubKey) { if !res.decode(bs) { return } - //if res.key != *fromKey { - // return - //} res.key = *fromKey r.core.dht.handleRes(&res) } diff --git a/src/yggdrasil/udp.go b/src/yggdrasil/udp.go index fc7ed49f..0a04e7f0 100644 --- a/src/yggdrasil/udp.go +++ b/src/yggdrasil/udp.go @@ -74,8 +74,6 @@ func (iface *udpInterface) init(core *Core, addr string) { if err != nil { panic(err) } - //iface.sock.SetReadBuffer(1048576) - //iface.sock.SetWriteBuffer(1048576) iface.conns = make(map[connAddr]*connInfo) go iface.reader() } @@ -99,7 +97,6 @@ func (iface *udpInterface) startConn(info *connInfo) { defer ticker.Stop() defer func() { // Cleanup - // FIXME this still leaks a peer struct iface.mutex.Lock() delete(iface.conns, info.addr) iface.mutex.Unlock() @@ -178,51 +175,18 @@ func (iface *udpInterface) handleKeys(msg []byte, addr connAddr) { if ifce != nil && err == nil { conn.chunkSize = uint16(ifce.MTU) - 60 - 8 - 3 } - //conn.chunkSize = 65535 - 8 - 3 } - /* - conn.in = func (msg []byte) { conn.peer.handlePacket(msg, conn.linkIn) } - conn.peer.out = func (msg []byte) { - start := time.Now() - iface.sock.WriteToUDP(msg, udpAddr) - timed := time.Since(start) - conn.peer.updateBandwidth(len(msg), timed) - util_putBytes(msg) - } // Old version, always one syscall per packet - //*/ - /* - conn.peer.out = func (msg []byte) { - defer func() { recover() }() - select { - case conn.out<-msg: - default: util_putBytes(msg) - } - } - go func () { - for msg := range conn.out { - start := time.Now() - iface.sock.WriteToUDP(msg, udpAddr) - timed := time.Since(start) - conn.peer.updateBandwidth(len(msg), timed) - util_putBytes(msg) - } - }() - //*/ - //* var inChunks uint8 var inBuf []byte conn.in = func(bs []byte) { //defer util_putBytes(bs) chunks, chunk, count, payload := udp_decode(bs) - //iface.core.log.Println("DEBUG:", addr, chunks, chunk, count, len(payload)) - //iface.core.log.Println("DEBUG: payload:", payload) if count != conn.countIn { inChunks = 0 inBuf = inBuf[:0] conn.countIn = count } if chunk <= chunks && chunk == inChunks+1 { - //iface.core.log.Println("GOING:", addr, chunks, chunk, count, len(payload)) inChunks += 1 inBuf = append(inBuf, payload...) if chunks != chunk { @@ -230,7 +194,6 @@ func (iface *udpInterface) handleKeys(msg []byte, addr connAddr) { } msg := append(util_getBytes(), inBuf...) conn.peer.handlePacket(msg, conn.linkIn) - //iface.core.log.Println("DONE:", addr, chunks, chunk, count, len(payload)) } } conn.peer.out = func(msg []byte) { @@ -251,7 +214,6 @@ func (iface *udpInterface) handleKeys(msg []byte, addr connAddr) { chunks, bs = append(chunks, bs[:conn.chunkSize]), bs[conn.chunkSize:] } chunks = append(chunks, bs) - //iface.core.log.Println("DEBUG: out chunks:", len(chunks), len(msg)) if len(chunks) > 255 { continue } @@ -266,7 +228,6 @@ func (iface *udpInterface) handleKeys(msg []byte, addr connAddr) { conn.countOut += 1 conn.peer.updateBandwidth(len(msg), timed) util_putBytes(msg) - //iface.core.log.Println("DEBUG: sent:", len(msg)) } }() //*/ @@ -298,16 +259,12 @@ func (iface *udpInterface) handlePacket(msg []byte, addr connAddr) { func (iface *udpInterface) reader() { bs := make([]byte, 65536) // This needs to be large enough for everything... for { - //iface.core.log.Println("Starting read") n, udpAddr, err := iface.sock.ReadFromUDP(bs) - //iface.core.log.Println("Read", n, udpAddr.String(), err) //iface.core.log.Println("DEBUG: read:", bs[0], bs[1], bs[2], n) if err != nil { panic(err) break } - //iface.core.log.Println("DEBUG: recv len:", n) - //msg := append(util_getBytes(), bs[:n]...) msg := bs[:n] var addr connAddr addr.fromUDPAddr(udpAddr) @@ -330,9 +287,6 @@ func (iface *udpInterface) reader() { //////////////////////////////////////////////////////////////////////////////// -//const udp_chunkSize = 508 // Apparently the maximum guaranteed safe IPv4 size -//const udp_chunkSize = 65535 - 3 - 8 - func udp_decode(bs []byte) (chunks, chunk, count uint8, payload []byte) { if len(bs) >= 3 { chunks, chunk, count, payload = bs[0], bs[1], bs[2], bs[3:] diff --git a/src/yggdrasil/wire.go b/src/yggdrasil/wire.go index 379ef249..167a97d5 100644 --- a/src/yggdrasil/wire.go +++ b/src/yggdrasil/wire.go @@ -21,7 +21,6 @@ const ( wire_DHTLookupResponse // inside protocol traffic header wire_SearchRequest // inside protocol traffic header wire_SearchResponse // inside protocol traffic header - wire_Keys // udp key packet (boxPub, sigPub) ) // Encode uint64 using a variable length scheme @@ -112,8 +111,6 @@ func wire_put_coords(coords []byte, bs []byte) []byte { func wire_decode_coords(packet []byte) ([]byte, int) { coordLen, coordBegin := wire_decode_uint64(packet) coordEnd := coordBegin + int(coordLen) - //if coordBegin == 0 { panic("No coords found") } // Testing - //if coordEnd > len(packet) { panic("Packet too short") } // Testing if coordBegin == 0 || coordEnd > len(packet) { return nil, 0 } @@ -138,7 +135,6 @@ func (m *msgAnnounce) encode() []byte { bs = append(bs, wire_encode_uint64(wire_intToUint(m.tstamp))...) bs = append(bs, wire_encode_uint64(m.seq)...) bs = append(bs, wire_encode_uint64(m.len)...) - //bs = append(bs, wire_encode_uint64(m.Deg)...) bs = append(bs, wire_encode_uint64(m.rseq)...) return bs } @@ -159,7 +155,6 @@ func (m *msgAnnounce) decode(bs []byte) bool { return false case !wire_chop_uint64(&m.len, &bs): return false - //case !wire_chop_uint64(&m.Deg, &bs): return false case !wire_chop_uint64(&m.rseq, &bs): return false } @@ -381,16 +376,12 @@ func (p *wire_protoTrafficPacket) decode(bs []byte) bool { } type wire_linkProtoTrafficPacket struct { - //toKey boxPubKey - //fromKey boxPubKey nonce boxNonce payload []byte } func (p *wire_linkProtoTrafficPacket) encode() []byte { bs := wire_encode_uint64(wire_LinkProtocolTraffic) - //bs = append(bs, p.toKey[:]...) - //bs = append(bs, p.fromKey[:]...) bs = append(bs, p.nonce[:]...) bs = append(bs, p.payload...) return bs @@ -403,10 +394,6 @@ func (p *wire_linkProtoTrafficPacket) decode(bs []byte) bool { return false case pType != wire_LinkProtocolTraffic: return false - //case !wire_chop_slice(p.toKey[:], &bs): - // return false - //case !wire_chop_slice(p.fromKey[:], &bs): - // return false case !wire_chop_slice(p.nonce[:], &bs): return false } @@ -468,7 +455,6 @@ func (p *sessionPing) decode(bs []byte) bool { func (r *dhtReq) encode() []byte { coords := wire_encode_coords(r.coords) bs := wire_encode_uint64(wire_DHTLookupRequest) - //bs = append(bs, r.key[:]...) bs = append(bs, coords...) bs = append(bs, r.dest[:]...) return bs @@ -481,8 +467,6 @@ func (r *dhtReq) decode(bs []byte) bool { return false case pType != wire_DHTLookupRequest: return false - //case !wire_chop_slice(r.key[:], &bs): - // return false case !wire_chop_coords(&r.coords, &bs): return false case !wire_chop_slice(r.dest[:], &bs): @@ -495,7 +479,6 @@ func (r *dhtReq) decode(bs []byte) bool { func (r *dhtRes) encode() []byte { coords := wire_encode_coords(r.coords) bs := wire_encode_uint64(wire_DHTLookupResponse) - //bs = append(bs, r.key[:]...) bs = append(bs, coords...) bs = append(bs, r.dest[:]...) for _, info := range r.infos { @@ -513,8 +496,6 @@ func (r *dhtRes) decode(bs []byte) bool { return false case pType != wire_DHTLookupResponse: return false - //case !wire_chop_slice(r.key[:], &bs): - // return false case !wire_chop_coords(&r.coords, &bs): return false case !wire_chop_slice(r.dest[:], &bs): diff --git a/yggdrasil.go b/yggdrasil.go index 110cd37f..50a9c63c 100644 --- a/yggdrasil.go +++ b/yggdrasil.go @@ -118,7 +118,7 @@ func generateConfig() *nodeConfig { cfg.Multicast = true cfg.LinkLocal = "" cfg.IfName = "auto" - cfg.IfMTU = 1280 //65535 + cfg.IfMTU = 1280 if runtime.GOOS == "windows" { cfg.IfTAPMode = true } else {