From f304543ddfeb2084d602b5bd826c6bc41b4b502b Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Thu, 25 Dec 2014 14:02:53 +0000 Subject: [PATCH] refactor: move definition of Peer and related types --- router/peer.go | 22 ++++++++++++++++++++++ router/types.go | 21 --------------------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/router/peer.go b/router/peer.go index 5525caee..bd27573e 100644 --- a/router/peer.go +++ b/router/peer.go @@ -5,8 +5,19 @@ import ( "log" "net" "sort" + "sync" ) +type Peer struct { + sync.RWMutex + Name PeerName + NameByte []byte + UID uint64 + version uint64 + localRefCount uint64 + connections map[PeerName]Connection +} + func NewPeer(name PeerName, uid uint64, version uint64) *Peer { if uid == 0 { uid = randUint64() @@ -144,6 +155,17 @@ func (peer *Peer) Routes(stopAt *Peer, symmetric bool) (bool, map[PeerName]PeerN return false, routes } +type LocalPeer struct { + *Peer + Router *Router + queryChan chan<- *PeerInteraction +} + +type PeerInteraction struct { + Interaction + payload interface{} +} + func StartLocalPeer(name PeerName, router *Router) *LocalPeer { peer := &LocalPeer{Peer: NewPeer(name, 0, 0), Router: router} queryChan := make(chan *PeerInteraction, ChannelSize) diff --git a/router/types.go b/router/types.go index 97d27dc5..e6acb90b 100644 --- a/router/types.go +++ b/router/types.go @@ -25,27 +25,6 @@ type Router struct { LogFrame func(string, []byte, *layers.Ethernet) } -type Peer struct { - sync.RWMutex - Name PeerName - NameByte []byte - UID uint64 - version uint64 - localRefCount uint64 - connections map[PeerName]Connection -} - -type LocalPeer struct { - *Peer - Router *Router - queryChan chan<- *PeerInteraction -} - -type PeerInteraction struct { - Interaction - payload interface{} -} - type Connection interface { Local() *Peer Remote() *Peer