From: Sergey Matveev Date: Sun, 3 May 2015 21:09:14 +0000 (+0300) Subject: WriteToUDP is lighter than WriteTo X-Git-Tag: 3.1^2~4 X-Git-Url: http://www.git.cypherpunks.ru/?a=commitdiff_plain;h=e1fbc89e30babede2f69b0635624656fe9973846;p=govpn.git WriteToUDP is lighter than WriteTo Signed-off-by: Sergey Matveev --- diff --git a/transport.go b/transport.go index ddcfbf9..109c7f4 100644 --- a/transport.go +++ b/transport.go @@ -308,8 +308,8 @@ func (p *Peer) UDPProcess(udpPkt []byte, tap io.Writer, ready chan struct{}) boo return true } -type WriteToer interface { - WriteTo([]byte, net.Addr) (int, error) +type WriteToUDPer interface { + WriteToUDP([]byte, *net.UDPAddr) (int, error) } // Process incoming Ethernet packet. @@ -317,7 +317,7 @@ type WriteToer interface { // ready channel is TAPListen's synchronization channel used to tell him // that he is free to receive new packets. Encrypted and authenticated // packets will be sent to remote Peer side immediately. -func (p *Peer) EthProcess(ethPkt []byte, conn WriteToer, ready chan struct{}) { +func (p *Peer) EthProcess(ethPkt []byte, conn WriteToUDPer, ready chan struct{}) { now := time.Now() size := len(ethPkt) // If this heartbeat is necessary @@ -360,7 +360,7 @@ func (p *Peer) EthProcess(ethPkt []byte, conn WriteToer, ready chan struct{}) { } } p.LastSent = now - if _, err := conn.WriteTo(append(p.frame, p.tag[:]...), p.Addr); err != nil { + if _, err := conn.WriteToUDP(append(p.frame, p.tag[:]...), p.Addr); err != nil { log.Println("Error sending UDP", err) } } diff --git a/transport_test.go b/transport_test.go index 0dc54f9..51f0e6e 100644 --- a/transport_test.go +++ b/transport_test.go @@ -40,7 +40,7 @@ func init() { type Dummy struct{} -func (d *Dummy) WriteTo(b []byte, addr net.Addr) (int, error) { +func (d *Dummy) WriteToUDP(b []byte, addr *net.UDPAddr) (int, error) { ciphertext = b return len(b), nil }