LocalPeer shouldn't have to know about remote UDP address
...and LocalConnection shouldn't have to remember it
This commit is contained in:
1 parent
ad15e5a234
commit
e7ff6a2191
3 files changed
+23
-24
No files matched your search
+18
-14
@@ -40,17 +40,16 @@ type RemoteConnection struct {
|
|||||||
type LocalConnection struct {
|
type LocalConnection struct {
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
RemoteConnection
|
RemoteConnection
|
||||||
TCPConn *net.TCPConn
|
TCPConn *net.TCPConn
|
||||||
version byte
|
version byte
|
||||||
tcpSender TCPSender
|
tcpSender TCPSender
|
||||||
remoteUDPAddr *net.UDPAddr
|
SessionKey *[32]byte
|
||||||
SessionKey *[32]byte
|
heartbeatTCP *time.Ticker
|
||||||
heartbeatTCP *time.Ticker
|
Router *Router
|
||||||
Router *Router
|
uid uint64
|
||||||
uid uint64
|
actionChan chan<- ConnectionAction
|
||||||
actionChan chan<- ConnectionAction
|
finished <-chan struct{} // closed to signal that actorLoop has finished
|
||||||
finished <-chan struct{} // closed to signal that actorLoop has finished
|
forwarder OverlayForwarder
|
||||||
forwarder OverlayForwarder
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ConnectionAction func() error
|
type ConnectionAction func() error
|
||||||
@@ -83,7 +82,7 @@ func (conn *RemoteConnection) ErrorLog(args ...interface{}) {
|
|||||||
|
|
||||||
// Does not return anything. If the connection is successful, it will
|
// Does not return anything. If the connection is successful, it will
|
||||||
// end up in the local peer's connections map.
|
// end up in the local peer's connections map.
|
||||||
func StartLocalConnection(connRemote *RemoteConnection, tcpConn *net.TCPConn, udpAddr *net.UDPAddr, router *Router, acceptNewPeer bool) {
|
func StartLocalConnection(connRemote *RemoteConnection, tcpConn *net.TCPConn, router *Router, acceptNewPeer bool) {
|
||||||
if connRemote.local != router.Ourself.Peer {
|
if connRemote.local != router.Ourself.Peer {
|
||||||
log.Fatal("Attempt to create local connection from a peer which is not ourself")
|
log.Fatal("Attempt to create local connection from a peer which is not ourself")
|
||||||
}
|
}
|
||||||
@@ -94,7 +93,6 @@ func StartLocalConnection(connRemote *RemoteConnection, tcpConn *net.TCPConn, ud
|
|||||||
RemoteConnection: *connRemote,
|
RemoteConnection: *connRemote,
|
||||||
Router: router,
|
Router: router,
|
||||||
TCPConn: tcpConn,
|
TCPConn: tcpConn,
|
||||||
remoteUDPAddr: udpAddr,
|
|
||||||
uid: randUint64(),
|
uid: randUint64(),
|
||||||
actionChan: actionChan,
|
actionChan: actionChan,
|
||||||
finished: finished}
|
finished: finished}
|
||||||
@@ -192,10 +190,16 @@ func (conn *LocalConnection) run(actionChan <-chan ConnectionAction, finished ch
|
|||||||
|
|
||||||
conn.Log("connection ready; using protocol version", conn.version)
|
conn.Log("connection ready; using protocol version", conn.version)
|
||||||
|
|
||||||
|
var remoteAddr *net.UDPAddr
|
||||||
|
if conn.outbound {
|
||||||
|
tcpAddr := conn.TCPConn.RemoteAddr().(*net.TCPAddr)
|
||||||
|
remoteAddr = &net.UDPAddr{IP: tcpAddr.IP, Port: tcpAddr.Port, Zone: tcpAddr.Zone}
|
||||||
|
}
|
||||||
|
|
||||||
params := ForwarderParams{
|
params := ForwarderParams{
|
||||||
RemotePeer: conn.remote,
|
RemotePeer: conn.remote,
|
||||||
LocalIP: conn.TCPConn.LocalAddr().(*net.TCPAddr).IP,
|
LocalIP: conn.TCPConn.LocalAddr().(*net.TCPAddr).IP,
|
||||||
RemoteAddr: conn.remoteUDPAddr,
|
RemoteAddr: remoteAddr,
|
||||||
ConnUID: conn.uid,
|
ConnUID: conn.uid,
|
||||||
Crypto: conn.forwarderCrypto(),
|
Crypto: conn.forwarderCrypto(),
|
||||||
SendControlMessage: conn.sendOverlayControlMessage,
|
SendControlMessage: conn.sendOverlayControlMessage,
|
||||||
|
|||||||
@@ -62,21 +62,16 @@ func (peer *LocalPeer) CreateConnection(peerAddr string, acceptNewPeer bool) err
|
|||||||
if err := peer.checkConnectionLimit(); err != nil {
|
if err := peer.checkConnectionLimit(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
tcpAddr, tcpErr := net.ResolveTCPAddr("tcp4", peerAddr)
|
tcpAddr, err := net.ResolveTCPAddr("tcp4", peerAddr)
|
||||||
udpAddr, udpErr := net.ResolveUDPAddr("udp4", peerAddr)
|
if err != nil {
|
||||||
if tcpErr != nil || udpErr != nil {
|
return err
|
||||||
// they really should have the same value, but just in case...
|
|
||||||
if tcpErr == nil {
|
|
||||||
return udpErr
|
|
||||||
}
|
|
||||||
return tcpErr
|
|
||||||
}
|
}
|
||||||
tcpConn, err := net.DialTCP("tcp4", nil, tcpAddr)
|
tcpConn, err := net.DialTCP("tcp4", nil, tcpAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
connRemote := NewRemoteConnection(peer.Peer, nil, tcpConn.RemoteAddr().String(), true, false)
|
connRemote := NewRemoteConnection(peer.Peer, nil, tcpConn.RemoteAddr().String(), true, false)
|
||||||
StartLocalConnection(connRemote, tcpConn, udpAddr, peer.router, acceptNewPeer)
|
StartLocalConnection(connRemote, tcpConn, peer.router, acceptNewPeer)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -171,7 +171,7 @@ func (router *Router) acceptTCP(tcpConn *net.TCPConn) {
|
|||||||
remoteAddrStr := tcpConn.RemoteAddr().String()
|
remoteAddrStr := tcpConn.RemoteAddr().String()
|
||||||
log.Printf("->[%s] connection accepted", remoteAddrStr)
|
log.Printf("->[%s] connection accepted", remoteAddrStr)
|
||||||
connRemote := NewRemoteConnection(router.Ourself.Peer, nil, remoteAddrStr, false, false)
|
connRemote := NewRemoteConnection(router.Ourself.Peer, nil, remoteAddrStr, false, false)
|
||||||
StartLocalConnection(connRemote, tcpConn, nil, router, true)
|
StartLocalConnection(connRemote, tcpConn, router, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (router *Router) handleForwardedPacket(key ForwardPacketKey) FlowOp {
|
func (router *Router) handleForwardedPacket(key ForwardPacketKey) FlowOp {
|
||||||
|
|||||||
Reference in new issue
Block a user