Eliminate the Start method on LocalConnection
This commit is contained in:
1 parent
8a54af92ef
commit
4d0ca39f97
3 files changed
+11
-16
No files matched your search
+9
-12
@@ -97,26 +97,23 @@ func (conn *RemoteConnection) String() string {
|
|||||||
return fmt.Sprint("Connection ", from, "->", to)
|
return fmt.Sprint("Connection ", from, "->", to)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLocalConnection(connRemote *RemoteConnection, tcpConn *net.TCPConn, udpAddr *net.UDPAddr, router *Router) *LocalConnection {
|
// Does not return anything. If the connection is successful, it will
|
||||||
|
// end up in the local peer's connections map.
|
||||||
|
func StartLocalConnection(connRemote *RemoteConnection, tcpConn *net.TCPConn, udpAddr *net.UDPAddr, 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")
|
||||||
}
|
}
|
||||||
// NB, we're taking a copy of connRemote here.
|
// NB, we're taking a copy of connRemote here.
|
||||||
return &LocalConnection{
|
actionChan := make(chan ConnectionAction, ChannelSize)
|
||||||
|
finished := make(chan struct{})
|
||||||
|
conn := &LocalConnection{
|
||||||
RemoteConnection: *connRemote,
|
RemoteConnection: *connRemote,
|
||||||
Router: router,
|
Router: router,
|
||||||
TCPConn: tcpConn,
|
TCPConn: tcpConn,
|
||||||
remoteUDPAddr: udpAddr,
|
remoteUDPAddr: udpAddr,
|
||||||
effectivePMTU: DefaultPMTU}
|
effectivePMTU: DefaultPMTU,
|
||||||
}
|
actionChan: actionChan,
|
||||||
|
finished: finished}
|
||||||
// Async. Does not return anything. If the connection is successful,
|
|
||||||
// it will end up in the local peer's connections map.
|
|
||||||
func (conn *LocalConnection) Start(acceptNewPeer bool) {
|
|
||||||
actionChan := make(chan ConnectionAction, ChannelSize)
|
|
||||||
conn.actionChan = actionChan
|
|
||||||
finished := make(chan struct{})
|
|
||||||
conn.finished = finished
|
|
||||||
go conn.run(actionChan, finished, acceptNewPeer)
|
go conn.run(actionChan, finished, acceptNewPeer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -132,8 +132,7 @@ func (peer *LocalPeer) CreateConnection(peerAddr string, acceptNewPeer bool) err
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
connRemote := NewRemoteConnection(peer.Peer, nil, tcpConn.RemoteAddr().String(), true, false)
|
connRemote := NewRemoteConnection(peer.Peer, nil, tcpConn.RemoteAddr().String(), true, false)
|
||||||
connLocal := NewLocalConnection(connRemote, tcpConn, udpAddr, peer.router)
|
StartLocalConnection(connRemote, tcpConn, udpAddr, peer.router, acceptNewPeer)
|
||||||
connLocal.Start(acceptNewPeer)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -209,8 +209,7 @@ func (router *Router) acceptTCP(tcpConn *net.TCPConn) {
|
|||||||
remoteAddrStr := tcpConn.RemoteAddr().String()
|
remoteAddrStr := tcpConn.RemoteAddr().String()
|
||||||
log.Printf("->[%s] connection accepted\n", remoteAddrStr)
|
log.Printf("->[%s] connection accepted\n", remoteAddrStr)
|
||||||
connRemote := NewRemoteConnection(router.Ourself.Peer, nil, remoteAddrStr, false, false)
|
connRemote := NewRemoteConnection(router.Ourself.Peer, nil, remoteAddrStr, false, false)
|
||||||
connLocal := NewLocalConnection(connRemote, tcpConn, nil, router)
|
StartLocalConnection(connRemote, tcpConn, nil, router, true)
|
||||||
connLocal.Start(true)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (router *Router) listenUDP(localPort int, po PacketSink) *net.UDPConn {
|
func (router *Router) listenUDP(localPort int, po PacketSink) *net.UDPConn {
|
||||||
|
|||||||
Reference in new issue
Block a user