5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-09-20 02:32:32 +00:00

have listener return a net.Conn, adjust yggdrasil.Conn to match this interface

This commit is contained in:
Arceliar 2019-10-19 15:10:28 -05:00
parent d307ad4c91
commit cb40874f97
4 changed files with 12 additions and 11 deletions

View File

@ -93,7 +93,7 @@ func (s *tunConn) _read(bs []byte) (err error) {
skip = true skip = true
} else if key, err := s.tun.ckr.getPublicKeyForAddress(srcAddr, addrlen); err == nil { } else if key, err := s.tun.ckr.getPublicKeyForAddress(srcAddr, addrlen); err == nil {
srcNodeID := crypto.GetNodeID(&key) srcNodeID := crypto.GetNodeID(&key)
if s.conn.RemoteAddr() == *srcNodeID { if *s.conn.RemoteAddr().(*crypto.NodeID) == *srcNodeID {
// This is the one allowed CKR case, where source and destination addresses are both good // This is the one allowed CKR case, where source and destination addresses are both good
} else { } else {
// The CKR key associated with this address doesn't match the sender's NodeID // The CKR key associated with this address doesn't match the sender's NodeID
@ -170,7 +170,7 @@ func (s *tunConn) _write(bs []byte) (err error) {
skip = true skip = true
} else if key, err := s.tun.ckr.getPublicKeyForAddress(dstAddr, addrlen); err == nil { } else if key, err := s.tun.ckr.getPublicKeyForAddress(dstAddr, addrlen); err == nil {
dstNodeID := crypto.GetNodeID(&key) dstNodeID := crypto.GetNodeID(&key)
if s.conn.RemoteAddr() == *dstNodeID { if *s.conn.RemoteAddr().(*crypto.NodeID) == *dstNodeID {
// This is the one allowed CKR case, where source and destination addresses are both good // This is the one allowed CKR case, where source and destination addresses are both good
} else { } else {
// The CKR key associated with this address doesn't match the sender's NodeID // The CKR key associated with this address doesn't match the sender's NodeID

View File

@ -219,7 +219,7 @@ func (tun *TunAdapter) handler() error {
return err return err
} }
phony.Block(tun, func() { phony.Block(tun, func() {
if _, err := tun._wrap(conn); err != nil { if _, err := tun._wrap(conn.(*yggdrasil.Conn)); err != nil {
// Something went wrong when storing the connection, typically that // Something went wrong when storing the connection, typically that
// something already exists for this address or subnet // something already exists for this address or subnet
tun.log.Debugln("TUN/TAP handler wrap:", err) tun.log.Debugln("TUN/TAP handler wrap:", err)
@ -237,9 +237,9 @@ func (tun *TunAdapter) _wrap(conn *yggdrasil.Conn) (c *tunConn, err error) {
} }
c = &s c = &s
// Get the remote address and subnet of the other side // Get the remote address and subnet of the other side
remoteNodeID := conn.RemoteAddr() remoteNodeID := conn.RemoteAddr().(*crypto.NodeID)
s.addr = *address.AddrForNodeID(&remoteNodeID) s.addr = *address.AddrForNodeID(remoteNodeID)
s.snet = *address.SubnetForNodeID(&remoteNodeID) s.snet = *address.SubnetForNodeID(remoteNodeID)
// Work out if this is already a destination we already know about // Work out if this is already a destination we already know about
atc, aok := tun.addrToConn[s.addr] atc, aok := tun.addrToConn[s.addr]
stc, sok := tun.subnetToConn[s.snet] stc, sok := tun.subnetToConn[s.snet]

View File

@ -3,6 +3,7 @@ package yggdrasil
import ( import (
"errors" "errors"
"fmt" "fmt"
"net"
"time" "time"
"github.com/yggdrasil-network/yggdrasil-go/src/crypto" "github.com/yggdrasil-network/yggdrasil-go/src/crypto"
@ -348,14 +349,14 @@ func (c *Conn) Close() (err error) {
// LocalAddr returns the complete node ID of the local side of the connection. // LocalAddr returns the complete node ID of the local side of the connection.
// This is always going to return your own node's node ID. // This is always going to return your own node's node ID.
func (c *Conn) LocalAddr() crypto.NodeID { func (c *Conn) LocalAddr() net.Addr {
return *crypto.GetNodeID(&c.core.boxPub) return crypto.GetNodeID(&c.core.boxPub)
} }
// RemoteAddr returns the complete node ID of the remote side of the connection. // RemoteAddr returns the complete node ID of the remote side of the connection.
func (c *Conn) RemoteAddr() crypto.NodeID { func (c *Conn) RemoteAddr() net.Addr {
// RemoteAddr is set during the dial or accept, and isn't changed, so it's safe to access directly // RemoteAddr is set during the dial or accept, and isn't changed, so it's safe to access directly
return *c.nodeID return c.nodeID
} }
// SetDeadline is equivalent to calling both SetReadDeadline and // SetDeadline is equivalent to calling both SetReadDeadline and

View File

@ -13,7 +13,7 @@ type Listener struct {
} }
// Accept blocks until a new incoming session is received // Accept blocks until a new incoming session is received
func (l *Listener) Accept() (*Conn, error) { func (l *Listener) Accept() (net.Conn, error) {
select { select {
case c, ok := <-l.conn: case c, ok := <-l.conn:
if !ok { if !ok {