From d10126f883ad39567248540347b5469956ab8b2e Mon Sep 17 00:00:00 2001 From: Mathias Hall-Andersen Date: Sat, 18 Nov 2017 23:34:02 +0100 Subject: Moved endpoint into interface and simplified peer --- src/conn.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/conn.go') diff --git a/src/conn.go b/src/conn.go index 3cf00ab..74bb075 100644 --- a/src/conn.go +++ b/src/conn.go @@ -7,26 +7,28 @@ import ( "net" ) -type UDPBind interface { +/* A Bind handles listening on a port for both IPv6 and IPv4 UDP traffic + */ +type Bind interface { SetMark(value uint32) error - ReceiveIPv6(buff []byte, end *Endpoint) (int, error) - ReceiveIPv4(buff []byte, end *Endpoint) (int, error) - Send(buff []byte, end *Endpoint) error + ReceiveIPv6(buff []byte) (int, Endpoint, error) + ReceiveIPv4(buff []byte) (int, Endpoint, error) + Send(buff []byte, end Endpoint) error Close() error } /* An Endpoint maintains the source/destination caching for a peer * - * dst : the remote address of a peer + * dst : the remote address of a peer ("endpoint" in uapi terminology) * src : the local address from which datagrams originate going to the peer - * */ -type UDPEndpoint interface { +type Endpoint interface { ClearSrc() // clears the source address ClearDst() // clears the destination address SrcToString() string // returns the local source address (ip:port) DstToString() string // returns the destination address (ip:port) DstToBytes() []byte // used for mac2 cookie calculations + SetDst(string) error // used for manually setting the endpoint (uapi) DstIP() net.IP SrcIP() net.IP } @@ -107,7 +109,9 @@ func UpdateUDPListener(device *Device) error { for _, peer := range device.peers { peer.mutex.Lock() - peer.endpoint.value.ClearSrc() + if peer.endpoint != nil { + peer.endpoint.ClearSrc() + } peer.mutex.Unlock() } -- cgit v1.2.3