Re-order Connection fields more consistently
This commit is contained in:
1 parent
89fce7f98a
commit
d87e13b999
3 files changed
+22
-40
No files matched your search
+13
-31
@@ -13,10 +13,10 @@ import (
|
|||||||
type Connection interface {
|
type Connection interface {
|
||||||
Local() *Peer
|
Local() *Peer
|
||||||
Remote() *Peer
|
Remote() *Peer
|
||||||
BreakTie(Connection) ConnectionTieBreak
|
|
||||||
RemoteTCPAddr() string
|
RemoteTCPAddr() string
|
||||||
Established() bool
|
|
||||||
Outbound() bool
|
Outbound() bool
|
||||||
|
Established() bool
|
||||||
|
BreakTie(Connection) ConnectionTieBreak
|
||||||
Shutdown(error)
|
Shutdown(error)
|
||||||
Log(args ...interface{})
|
Log(args ...interface{})
|
||||||
}
|
}
|
||||||
@@ -33,8 +33,8 @@ type RemoteConnection struct {
|
|||||||
local *Peer
|
local *Peer
|
||||||
remote *Peer
|
remote *Peer
|
||||||
remoteTCPAddr string
|
remoteTCPAddr string
|
||||||
established bool
|
|
||||||
outbound bool
|
outbound bool
|
||||||
|
established bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type LocalConnection struct {
|
type LocalConnection struct {
|
||||||
@@ -68,41 +68,23 @@ type ConnectionInteraction struct {
|
|||||||
payload interface{}
|
payload interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRemoteConnection(from, to *Peer, tcpAddr string, established bool, outbound bool) *RemoteConnection {
|
func NewRemoteConnection(from, to *Peer, tcpAddr string, outbound bool, established bool) *RemoteConnection {
|
||||||
return &RemoteConnection{
|
return &RemoteConnection{
|
||||||
local: from,
|
local: from,
|
||||||
remote: to,
|
remote: to,
|
||||||
remoteTCPAddr: tcpAddr,
|
remoteTCPAddr: tcpAddr,
|
||||||
|
outbound: outbound,
|
||||||
established: established,
|
established: established,
|
||||||
outbound: outbound}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (conn *RemoteConnection) Local() *Peer {
|
func (conn *RemoteConnection) Local() *Peer { return conn.local }
|
||||||
return conn.local
|
func (conn *RemoteConnection) Remote() *Peer { return conn.remote }
|
||||||
}
|
func (conn *RemoteConnection) RemoteTCPAddr() string { return conn.remoteTCPAddr }
|
||||||
|
func (conn *RemoteConnection) Outbound() bool { return conn.outbound }
|
||||||
func (conn *RemoteConnection) Remote() *Peer {
|
func (conn *RemoteConnection) Established() bool { return conn.established }
|
||||||
return conn.remote
|
func (conn *RemoteConnection) BreakTie(Connection) ConnectionTieBreak { return TieBreakTied }
|
||||||
}
|
func (conn *RemoteConnection) Shutdown(error) {}
|
||||||
|
|
||||||
func (conn *RemoteConnection) BreakTie(Connection) ConnectionTieBreak {
|
|
||||||
return TieBreakTied
|
|
||||||
}
|
|
||||||
|
|
||||||
func (conn *RemoteConnection) RemoteTCPAddr() string {
|
|
||||||
return conn.remoteTCPAddr
|
|
||||||
}
|
|
||||||
|
|
||||||
func (conn *RemoteConnection) Established() bool {
|
|
||||||
return conn.established
|
|
||||||
}
|
|
||||||
|
|
||||||
func (conn *RemoteConnection) Outbound() bool {
|
|
||||||
return conn.outbound
|
|
||||||
}
|
|
||||||
|
|
||||||
func (conn *RemoteConnection) Shutdown(error) {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (conn *RemoteConnection) Log(args ...interface{}) {
|
func (conn *RemoteConnection) Log(args ...interface{}) {
|
||||||
log.Println(append(append([]interface{}{}, fmt.Sprintf("->[%s]:", conn.remote.Name)), args...)...)
|
log.Println(append(append([]interface{}{}, fmt.Sprintf("->[%s]:", conn.remote.Name)), args...)...)
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ func (peer *LocalPeer) CreateConnection(peerAddr string, acceptNewPeer bool) err
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
connRemote := NewRemoteConnection(peer.Peer, nil, tcpConn.RemoteAddr().String(), false, true)
|
connRemote := NewRemoteConnection(peer.Peer, nil, tcpConn.RemoteAddr().String(), true, false)
|
||||||
connLocal := NewLocalConnection(connRemote, tcpConn, udpAddr, peer.Router)
|
connLocal := NewLocalConnection(connRemote, tcpConn, udpAddr, peer.Router)
|
||||||
connLocal.Start(acceptNewPeer)
|
connLocal.Start(acceptNewPeer)
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
+8
-8
@@ -267,8 +267,8 @@ func (peer *Peer) encode(enc *gob.Encoder) {
|
|||||||
checkFatal(connsEnc.Encode(conn.Remote().NameByte))
|
checkFatal(connsEnc.Encode(conn.Remote().NameByte))
|
||||||
checkFatal(connsEnc.Encode(conn.RemoteTCPAddr()))
|
checkFatal(connsEnc.Encode(conn.RemoteTCPAddr()))
|
||||||
// DANGER holding rlock on peer, going to take rlock on conn
|
// DANGER holding rlock on peer, going to take rlock on conn
|
||||||
checkFatal(connsEnc.Encode(conn.Established()))
|
|
||||||
checkFatal(connsEnc.Encode(conn.Outbound()))
|
checkFatal(connsEnc.Encode(conn.Outbound()))
|
||||||
|
checkFatal(connsEnc.Encode(conn.Established()))
|
||||||
}
|
}
|
||||||
checkFatal(enc.Encode(connsBuf.Bytes()))
|
checkFatal(enc.Encode(connsBuf.Bytes()))
|
||||||
}
|
}
|
||||||
@@ -305,24 +305,24 @@ func connsIterator(input []byte, fun func([]byte, string, bool, bool)) error {
|
|||||||
if err := dec.Decode(&foundAt); err != nil {
|
if err := dec.Decode(&foundAt); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var established bool
|
|
||||||
if err := dec.Decode(&established); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
var outbound bool
|
var outbound bool
|
||||||
if err := dec.Decode(&outbound); err != nil {
|
if err := dec.Decode(&outbound); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fun(nameByte, foundAt, established, outbound)
|
var established bool
|
||||||
|
if err := dec.Decode(&established); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fun(nameByte, foundAt, outbound, established)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func readConnsMap(peer *Peer, buf []byte, table map[PeerName]*Peer) map[PeerName]Connection {
|
func readConnsMap(peer *Peer, buf []byte, table map[PeerName]*Peer) map[PeerName]Connection {
|
||||||
conns := make(map[PeerName]Connection)
|
conns := make(map[PeerName]Connection)
|
||||||
if err := connsIterator(buf, func(nameByte []byte, remoteTCPAddr string, established bool, outbound bool) {
|
if err := connsIterator(buf, func(nameByte []byte, remoteTCPAddr string, outbound bool, established bool) {
|
||||||
name := PeerNameFromBin(nameByte)
|
name := PeerNameFromBin(nameByte)
|
||||||
remotePeer := table[name]
|
remotePeer := table[name]
|
||||||
conn := NewRemoteConnection(peer, remotePeer, remoteTCPAddr, established, outbound)
|
conn := NewRemoteConnection(peer, remotePeer, remoteTCPAddr, outbound, established)
|
||||||
conns[name] = conn
|
conns[name] = conn
|
||||||
}); err != io.EOF {
|
}); err != io.EOF {
|
||||||
// this should never happen since we've already successfully
|
// this should never happen since we've already successfully
|
||||||
|
|||||||
Reference in new issue
Block a user