Merge pull request #1643 from weaveworks/refactor-forwarder-remote-address
Refactor: remove knowledge of overlay connectivity details from Local{Peer,Connection}
This commit is contained in:
commit
3e99b71e0f
7 files changed
+48
-40
No files matched your search
+14
-15
@@ -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}
|
||||||
@@ -194,8 +192,9 @@ func (conn *LocalConnection) run(actionChan <-chan ConnectionAction, finished ch
|
|||||||
|
|
||||||
params := ForwarderParams{
|
params := ForwarderParams{
|
||||||
RemotePeer: conn.remote,
|
RemotePeer: conn.remote,
|
||||||
LocalIP: conn.TCPConn.LocalAddr().(*net.TCPAddr).IP,
|
LocalAddr: conn.TCPConn.LocalAddr().(*net.TCPAddr),
|
||||||
RemoteAddr: conn.remoteUDPAddr,
|
RemoteAddr: conn.TCPConn.RemoteAddr().(*net.TCPAddr),
|
||||||
|
Outbound: conn.outbound,
|
||||||
ConnUID: conn.uid,
|
ConnUID: conn.uid,
|
||||||
Crypto: conn.forwarderCrypto(),
|
Crypto: conn.forwarderCrypto(),
|
||||||
SendControlMessage: conn.sendOverlayControlMessage,
|
SendControlMessage: conn.sendOverlayControlMessage,
|
||||||
|
|||||||
+6
-5
@@ -523,15 +523,16 @@ func (fastdp fastDatapathOverlay) MakeForwarder(params ForwarderParams) (Overlay
|
|||||||
}
|
}
|
||||||
|
|
||||||
vxlanVportID := fastdp.mainVxlanVportID
|
vxlanVportID := fastdp.mainVxlanVportID
|
||||||
remoteAddr := params.RemoteAddr
|
var remoteAddr *net.UDPAddr
|
||||||
if remoteAddr != nil {
|
|
||||||
|
if params.Outbound {
|
||||||
|
remoteAddr = makeUDPAddr(params.RemoteAddr)
|
||||||
// The provided address contains the main weave port
|
// The provided address contains the main weave port
|
||||||
// number to connect to. We need to derive the vxlan
|
// number to connect to. We need to derive the vxlan
|
||||||
// port number from that.
|
// port number from that.
|
||||||
vxlanRemoteAddr := *params.RemoteAddr
|
vxlanRemoteAddr := *remoteAddr
|
||||||
vxlanRemoteAddr.Port++
|
vxlanRemoteAddr.Port++
|
||||||
remoteAddr = &vxlanRemoteAddr
|
remoteAddr = &vxlanRemoteAddr
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
vxlanVportID, err = fastdp.getVxlanVportID(remoteAddr.Port)
|
vxlanVportID, err = fastdp.getVxlanVportID(remoteAddr.Port)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -539,7 +540,7 @@ func (fastdp fastDatapathOverlay) MakeForwarder(params ForwarderParams) (Overlay
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
localIP, err := ipv4Bytes(params.LocalIP)
|
localIP, err := ipv4Bytes(params.LocalAddr.IP)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+12
-8
@@ -29,15 +29,19 @@ type Overlay interface {
|
|||||||
type ForwarderParams struct {
|
type ForwarderParams struct {
|
||||||
RemotePeer *Peer
|
RemotePeer *Peer
|
||||||
|
|
||||||
// The local IP address to use for sending. Derived from the
|
// The local address of the corresponding TCP connection. Used to
|
||||||
// local address of the corresponding TCP socket, so may
|
// derive the local IP address for sending. May differ for
|
||||||
// differ for different forwarders.
|
// different forwarders.
|
||||||
LocalIP net.IP
|
LocalAddr *net.TCPAddr
|
||||||
|
|
||||||
// The remote address to send to. nil if unknown, i.e. an
|
// The remote address of the corresponding TCP connection. Used to
|
||||||
// incoming connection, in which case the Overlay needs to
|
// determine the address to send to, but only if the TCP
|
||||||
// discover it (e.g. from incoming datagrams).
|
// connection is outbound. Otherwise the Overlay needs to discover
|
||||||
RemoteAddr *net.UDPAddr
|
// it (e.g. from incoming datagrams).
|
||||||
|
RemoteAddr *net.TCPAddr
|
||||||
|
|
||||||
|
// Is the corresponding TCP connection outbound?
|
||||||
|
Outbound bool
|
||||||
|
|
||||||
// Unique identifier for this connection
|
// Unique identifier for this connection
|
||||||
ConnUID uint64
|
ConnUID uint64
|
||||||
|
|||||||
+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 {
|
||||||
|
|||||||
+7
-2
@@ -365,6 +365,11 @@ func (sleeve *SleeveOverlay) MakeForwarder(params ForwarderParams) (OverlayForwa
|
|||||||
confirmedChan := make(chan struct{})
|
confirmedChan := make(chan struct{})
|
||||||
finishedChan := make(chan struct{})
|
finishedChan := make(chan struct{})
|
||||||
|
|
||||||
|
var remoteAddr *net.UDPAddr
|
||||||
|
if params.Outbound {
|
||||||
|
remoteAddr = makeUDPAddr(params.RemoteAddr)
|
||||||
|
}
|
||||||
|
|
||||||
fwd := &sleeveForwarder{
|
fwd := &sleeveForwarder{
|
||||||
sleeve: sleeve,
|
sleeve: sleeve,
|
||||||
remotePeer: params.RemotePeer,
|
remotePeer: params.RemotePeer,
|
||||||
@@ -379,13 +384,13 @@ func (sleeve *SleeveOverlay) MakeForwarder(params ForwarderParams) (OverlayForwa
|
|||||||
finishedChan: finishedChan,
|
finishedChan: finishedChan,
|
||||||
establishedChan: make(chan struct{}),
|
establishedChan: make(chan struct{}),
|
||||||
errorChan: make(chan error, 1),
|
errorChan: make(chan error, 1),
|
||||||
remoteAddr: params.RemoteAddr,
|
remoteAddr: remoteAddr,
|
||||||
mtu: DefaultMTU,
|
mtu: DefaultMTU,
|
||||||
crypto: crypto,
|
crypto: crypto,
|
||||||
maxPayload: DefaultMTU - UDPOverhead,
|
maxPayload: DefaultMTU - UDPOverhead,
|
||||||
overheadDF: UDPOverhead + crypto.EncDF.PacketOverhead() +
|
overheadDF: UDPOverhead + crypto.EncDF.PacketOverhead() +
|
||||||
crypto.EncDF.FrameOverhead() + EthernetOverhead,
|
crypto.EncDF.FrameOverhead() + EthernetOverhead,
|
||||||
senderDF: newUDPSenderDF(params.LocalIP, sleeve.localPort),
|
senderDF: newUDPSenderDF(params.LocalAddr.IP, sleeve.localPort),
|
||||||
}
|
}
|
||||||
|
|
||||||
go fwd.run(aggChan, aggDFChan, specialChan, controlMsgChan,
|
go fwd.run(aggChan, aggDFChan, specialChan, controlMsgChan,
|
||||||
|
|||||||
@@ -104,6 +104,10 @@ func intmac(key uint64) (r net.HardwareAddr) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func makeUDPAddr(addr *net.TCPAddr) *net.UDPAddr {
|
||||||
|
return &net.UDPAddr{IP: addr.IP, Port: addr.Port, Zone: addr.Zone}
|
||||||
|
}
|
||||||
|
|
||||||
type ListOfPeers []*Peer
|
type ListOfPeers []*Peer
|
||||||
|
|
||||||
func (lop ListOfPeers) Len() int {
|
func (lop ListOfPeers) Len() int {
|
||||||
|
|||||||
Reference in new issue
Block a user