aboutsummaryrefslogtreecommitdiffstats
path: root/peer.go
diff options
context:
space:
mode:
authorMaran <maran.hidskes@gmail.com>2014-06-02 21:20:27 +0800
committerMaran <maran.hidskes@gmail.com>2014-06-02 21:20:27 +0800
commitfb6ff61730ed92ada68c9c5a5b3a6f9976a78161 (patch)
tree63cd039495d38dd047c231d52a3356bdb5e8b3f2 /peer.go
parentff8a834ccc630e85292968aaed8abc52044797f8 (diff)
downloaddexon-fb6ff61730ed92ada68c9c5a5b3a6f9976a78161.tar
dexon-fb6ff61730ed92ada68c9c5a5b3a6f9976a78161.tar.gz
dexon-fb6ff61730ed92ada68c9c5a5b3a6f9976a78161.tar.bz2
dexon-fb6ff61730ed92ada68c9c5a5b3a6f9976a78161.tar.lz
dexon-fb6ff61730ed92ada68c9c5a5b3a6f9976a78161.tar.xz
dexon-fb6ff61730ed92ada68c9c5a5b3a6f9976a78161.tar.zst
dexon-fb6ff61730ed92ada68c9c5a5b3a6f9976a78161.zip
Implemented Public Peer interface
Diffstat (limited to 'peer.go')
-rw-r--r--peer.go42
1 files changed, 37 insertions, 5 deletions
diff --git a/peer.go b/peer.go
index 6853a949d..71ad91461 100644
--- a/peer.go
+++ b/peer.go
@@ -129,7 +129,7 @@ type Peer struct {
diverted bool
blocksRequested int
- Version string
+ version string
}
func NewPeer(conn net.Conn, ethereum *Ethereum, inbound bool) *Peer {
@@ -160,7 +160,7 @@ func NewOutboundPeer(addr string, ethereum *Ethereum, caps Caps) *Peer {
connected: 0,
disconnect: 0,
caps: caps,
- Version: ethutil.Config.ClientString,
+ version: ethutil.Config.ClientString,
}
// Set up the connection in another goroutine so we don't block the main thread
@@ -184,6 +184,34 @@ func NewOutboundPeer(addr string, ethereum *Ethereum, caps Caps) *Peer {
return p
}
+// Getters
+func (p *Peer) Inbound() bool {
+ return p.inbound
+}
+func (p *Peer) LastSend() time.Time {
+ return p.lastSend
+}
+func (p *Peer) LastPong() int64 {
+ return p.lastPong
+}
+func (p *Peer) Host() []byte {
+ return p.host
+}
+func (p *Peer) Port() uint16 {
+ return p.port
+}
+func (p *Peer) Version() string {
+ return p.version
+}
+func (p *Peer) Connected() *int32 {
+ return &p.connected
+}
+
+// Setters
+func (p *Peer) SetVersion(version string) {
+ p.version = version
+}
+
// Outputs any RLP encoded data to the peer
func (p *Peer) QueueMessage(msg *ethwire.Msg) {
if atomic.LoadInt32(&p.connected) != 1 {
@@ -531,7 +559,7 @@ func (p *Peer) pushHandshake() error {
pubkey := keyRing.PublicKey
msg := ethwire.NewMessage(ethwire.MsgHandshakeTy, []interface{}{
- uint32(ProtocolVersion), uint32(0), p.Version, byte(p.caps), p.port, pubkey[1:],
+ uint32(ProtocolVersion), uint32(0), p.version, byte(p.caps), p.port, pubkey[1:],
})
p.QueueMessage(msg)
@@ -588,8 +616,12 @@ func (p *Peer) handleHandshake(msg *ethwire.Msg) {
// Set the peer's caps
p.caps = Caps(c.Get(3).Byte())
+
// Get a reference to the peers version
- p.Version = c.Get(2).Str()
+ versionString := c.Get(2).Str()
+ if len(versionString) > 0 {
+ p.SetVersion(c.Get(2).Str())
+ }
// Catch up with the connected peer
if !p.ethereum.IsUpToDate() {
@@ -615,7 +647,7 @@ func (p *Peer) String() string {
strConnectType = "disconnected"
}
- return fmt.Sprintf("[%s] (%s) %v %s [%s]", strConnectType, strBoundType, p.conn.RemoteAddr(), p.Version, p.caps)
+ return fmt.Sprintf("[%s] (%s) %v %s [%s]", strConnectType, strBoundType, p.conn.RemoteAddr(), p.version, p.caps)
}
func (p *Peer) SyncWithPeerToLastKnown() {