Cleanup, hub updates
This commit is contained in:
		| @@ -106,7 +106,7 @@ func main(listenIP string, port uint16) { | ||||
| 	// Intialize globals. | ||||
| 	localIP = config.PeerIP | ||||
| 	localPub = addrIsValid(config.PublicIP) | ||||
| 	privateKey = config.EncPrivKey | ||||
| 	privateKey = config.PrivKey | ||||
|  | ||||
| 	_iface = newIFWriter(iface) | ||||
| 	_conn = newConnWriter(conn) | ||||
|   | ||||
| @@ -14,8 +14,6 @@ const ( | ||||
| 	packetTypeSyn = iota + 1 | ||||
| 	packetTypeSynAck | ||||
| 	packetTypeAck | ||||
| 	packetTypeAddrReq | ||||
| 	packetTypeAddrResp | ||||
| ) | ||||
|  | ||||
| // ---------------------------------------------------------------------------- | ||||
| @@ -34,10 +32,6 @@ func (p *controlPacket) ParsePayload(buf []byte) (err error) { | ||||
| 		p.Payload, err = parseSynAckPacket(buf) | ||||
| 	case packetTypeAck: | ||||
| 		p.Payload, err = parseAckPacket(buf) | ||||
| 	case packetTypeAddrReq: | ||||
| 		p.Payload, err = parseAddrReqPacket(buf) | ||||
| 	case packetTypeAddrResp: | ||||
| 		p.Payload, err = parseAddrRespPacket(buf) | ||||
| 	default: | ||||
| 		return errUnknownPacketType | ||||
| 	} | ||||
| @@ -118,46 +112,3 @@ func parseAckPacket(buf []byte) (p ackPacket, err error) { | ||||
| 		Error() | ||||
| 	return | ||||
| } | ||||
|  | ||||
| // ---------------------------------------------------------------------------- | ||||
|  | ||||
| type addrReqPacket struct { | ||||
| 	TraceID uint64 | ||||
| } | ||||
|  | ||||
| func (p addrReqPacket) Marshal(buf []byte) []byte { | ||||
| 	return newBinWriter(buf). | ||||
| 		Byte(packetTypeAddrReq). | ||||
| 		Uint64(p.TraceID). | ||||
| 		Build() | ||||
| } | ||||
|  | ||||
| func parseAddrReqPacket(buf []byte) (p addrReqPacket, err error) { | ||||
| 	err = newBinReader(buf[1:]). | ||||
| 		Uint64(&p.TraceID). | ||||
| 		Error() | ||||
| 	return | ||||
| } | ||||
|  | ||||
| // ---------------------------------------------------------------------------- | ||||
|  | ||||
| type addrRespPacket struct { | ||||
| 	TraceID uint64 | ||||
| 	Addr    netip.AddrPort | ||||
| } | ||||
|  | ||||
| func (p addrRespPacket) Marshal(buf []byte) []byte { | ||||
| 	return newBinWriter(buf). | ||||
| 		Byte(packetTypeAddrResp). | ||||
| 		Uint64(p.TraceID). | ||||
| 		AddrPort(p.Addr). | ||||
| 		Build() | ||||
| } | ||||
|  | ||||
| func parseAddrRespPacket(buf []byte) (p addrRespPacket, err error) { | ||||
| 	err = newBinReader(buf[1:]). | ||||
| 		Uint64(&p.TraceID). | ||||
| 		AddrPort(&p.Addr). | ||||
| 		Error() | ||||
| 	return | ||||
| } | ||||
|   | ||||
| @@ -2,6 +2,7 @@ package node | ||||
|  | ||||
| import ( | ||||
| 	"crypto/rand" | ||||
| 	"net/netip" | ||||
| 	"reflect" | ||||
| 	"testing" | ||||
| ) | ||||
| @@ -24,7 +25,8 @@ func TestPacketSyn(t *testing.T) { | ||||
|  | ||||
| func TestPacketSynAck(t *testing.T) { | ||||
| 	in := synAckPacket{ | ||||
| 		TraceID: newTraceID(), | ||||
| 		TraceID:  newTraceID(), | ||||
| 		RecvAddr: netip.AddrPort{}, | ||||
| 	} | ||||
|  | ||||
| 	out, err := parseSynAckPacket(in.Marshal(make([]byte, bufferSize))) | ||||
|   | ||||
| @@ -102,12 +102,12 @@ func (s *peerSupervisor) _peerUpdate(peer *m.Peer) stateFunc { | ||||
| 	} | ||||
|  | ||||
| 	s.staged.IP = s.remoteIP | ||||
| 	s.staged.ControlCipher = newControlCipher(privateKey, peer.EncPubKey) | ||||
| 	s.staged.ControlCipher = newControlCipher(privateKey, peer.PubKey) | ||||
| 	s.staged.DataCipher = newDataCipher() | ||||
|  | ||||
| 	if ip, isValid := netip.AddrFromSlice(peer.PublicIP); isValid { | ||||
| 		s.remotePub = true | ||||
| 		s.staged.Relay = peer.Mediator | ||||
| 		s.staged.Relay = peer.Relay | ||||
| 		s.staged.RemoteAddr = netip.AddrPortFrom(ip, peer.Port) | ||||
| 	} | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user