]> Cypherpunks.ru repositories - govpn.git/commitdiff
WriteToUDP is lighter than WriteTo
authorSergey Matveev <stargrave@stargrave.org>
Sun, 3 May 2015 21:09:14 +0000 (00:09 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sun, 3 May 2015 21:09:14 +0000 (00:09 +0300)
Signed-off-by: Sergey Matveev <stargrave@stargrave.org>
transport.go
transport_test.go

index ddcfbf90dc28f21904f3230de0c6f9e5cea0adb4..109c7f4eda8a0f7163a565426dc6a476f4e9e69b 100644 (file)
@@ -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)
        }
 }
index 0dc54f992b24210a9623c8a60683651a5d6656c1..51f0e6e322f17efa25edfabe9484c8a587b6e134 100644 (file)
@@ -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
 }