wip: cleanup
This commit is contained in:
		| @@ -150,10 +150,6 @@ func (r *connReader) Read(buf []byte) (remoteAddr netip.AddrPort, h header, data | ||||
|  | ||||
| 		h.Parse(data) | ||||
|  | ||||
| 		if len(data) != headerSize+int(h.DataSize) { | ||||
| 			continue // Invalid header. | ||||
| 		} | ||||
|  | ||||
| 		peer := r.routing.Get(h.SourceIP) | ||||
| 		if peer == nil { | ||||
| 			continue | ||||
|   | ||||
| @@ -9,11 +9,10 @@ import ( | ||||
|  | ||||
| // Encrypting the packet will also set the header's DataSize field. | ||||
| func encryptPacket(h *header, sharedKey, data, out []byte) []byte { | ||||
| 	h.DataSize = uint16(len(data) + box.Overhead) | ||||
| 	out = out[:h.DataSize+headerSize] | ||||
| 	out = out[:headerSize] | ||||
| 	h.Marshal(out) | ||||
| 	box.SealAfterPrecomputation(out[headerSize:headerSize], data, (*[24]byte)(out[:headerSize]), (*[32]byte)(sharedKey)) | ||||
| 	return out | ||||
| 	b := box.SealAfterPrecomputation(out[headerSize:headerSize], data, (*[24]byte)(out[:headerSize]), (*[32]byte)(sharedKey)) | ||||
| 	return out[:len(b)+headerSize] | ||||
| } | ||||
|  | ||||
| func decryptPacket(sharedKey, packetAndHeader, out []byte) (decrypted []byte, ok bool) { | ||||
|   | ||||
| @@ -35,8 +35,8 @@ func TestEncryptDecryptPacket(t *testing.T) { | ||||
| 	h := header{ | ||||
| 		Counter:  2893749238, | ||||
| 		SourceIP: 5, | ||||
| 		ViaIP:    8, | ||||
| 		DestIP:   12, | ||||
| 		Forward:  1, | ||||
| 		Stream:   1, | ||||
| 	} | ||||
|  | ||||
| @@ -87,8 +87,8 @@ func BenchmarkEncryptPacket(b *testing.B) { | ||||
| 	h := header{ | ||||
| 		Counter:  2893749238, | ||||
| 		SourceIP: 5, | ||||
| 		ViaIP:    8, | ||||
| 		DestIP:   12, | ||||
| 		Forward:  1, | ||||
| 		Stream:   1, | ||||
| 	} | ||||
|  | ||||
| @@ -123,8 +123,8 @@ func BenchmarkDecryptPacket(b *testing.B) { | ||||
| 	h := header{ | ||||
| 		Counter:  2893749238, | ||||
| 		SourceIP: 5, | ||||
| 		ViaIP:    8, | ||||
| 		DestIP:   12, | ||||
| 		Forward:  1, | ||||
| 		Stream:   1, | ||||
| 	} | ||||
|  | ||||
|   | ||||
| @@ -13,8 +13,7 @@ type header struct { | ||||
| 	SourceIP byte | ||||
| 	DestIP   byte | ||||
| 	Forward  byte | ||||
| 	Stream   byte   // See stream* constants. | ||||
| 	DataSize uint16 // Data size following associated data. | ||||
| 	Stream   byte // See stream* constants. | ||||
| } | ||||
|  | ||||
| func (hdr *header) Parse(nb []byte) { | ||||
| @@ -23,7 +22,6 @@ func (hdr *header) Parse(nb []byte) { | ||||
| 	hdr.DestIP = nb[9] | ||||
| 	hdr.Forward = nb[10] | ||||
| 	hdr.Stream = nb[11] | ||||
| 	hdr.DataSize = *(*uint16)(unsafe.Pointer(&nb[12])) | ||||
| } | ||||
|  | ||||
| func (hdr header) Marshal(buf []byte) { | ||||
| @@ -32,5 +30,4 @@ func (hdr header) Marshal(buf []byte) { | ||||
| 	buf[9] = hdr.DestIP | ||||
| 	buf[10] = hdr.Forward | ||||
| 	buf[11] = hdr.Stream | ||||
| 	*(*uint16)(unsafe.Pointer(&buf[12])) = hdr.DataSize | ||||
| } | ||||
|   | ||||
| @@ -6,10 +6,9 @@ func TestHeaderMarshalParse(t *testing.T) { | ||||
| 	nIn := header{ | ||||
| 		Counter:  3212, | ||||
| 		SourceIP: 34, | ||||
| 		ViaIP:    20, | ||||
| 		DestIP:   200, | ||||
| 		Forward:  1, | ||||
| 		Stream:   44, | ||||
| 		DataSize: 1235, | ||||
| 	} | ||||
|  | ||||
| 	buf := make([]byte, headerSize) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user