aboutsummaryrefslogtreecommitdiffstats
path: root/peer.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-01-27 22:34:50 +0800
committerobscuren <geffobscura@gmail.com>2014-01-27 22:34:50 +0800
commit884f7928717394d631fbc8b721d8ee297f060e5b (patch)
tree76c934a745a7c31fb452d2c245035166d23e8d05 /peer.go
parent7931c6624cca041b373e97e17e43318633633250 (diff)
downloaddexon-884f7928717394d631fbc8b721d8ee297f060e5b.tar
dexon-884f7928717394d631fbc8b721d8ee297f060e5b.tar.gz
dexon-884f7928717394d631fbc8b721d8ee297f060e5b.tar.bz2
dexon-884f7928717394d631fbc8b721d8ee297f060e5b.tar.lz
dexon-884f7928717394d631fbc8b721d8ee297f060e5b.tar.xz
dexon-884f7928717394d631fbc8b721d8ee297f060e5b.tar.zst
dexon-884f7928717394d631fbc8b721d8ee297f060e5b.zip
Removed default connection
Diffstat (limited to 'peer.go')
-rw-r--r--peer.go28
1 files changed, 27 insertions, 1 deletions
diff --git a/peer.go b/peer.go
index f370580cf..d2328c393 100644
--- a/peer.go
+++ b/peer.go
@@ -68,9 +68,12 @@ func NewOutboundPeer(addr string, ethereum *Ethereum) *Peer {
// Set up the connection in another goroutine so we don't block the main thread
go func() {
- conn, err := net.Dial("tcp", addr)
+ conn, err := net.DialTimeout("tcp", addr, 30*time.Second)
+
if err != nil {
+ log.Println("Connection to peer failed", err)
p.Stop()
+ return
}
p.conn = conn
@@ -211,7 +214,30 @@ out:
p.requestedPeerList = false
}
case ethwire.MsgGetChainTy:
+ blocksFound := 0
+ l := msg.Data.Length()
+ // Check each SHA block hash from the message and determine whether
+ // the SHA is in the database
+ for i := 0; i < l; i++ {
+ if p.ethereum.BlockManager.BlockChain().HasBlock(msg.Data.Get(i).AsString()) {
+ blocksFound++
+ // TODO send reply
+ }
+ }
+
+ // If no blocks are found we send back a reply with msg not in chain
+ // and the last hash from get chain
+ if blocksFound == 0 {
+ lastHash := msg.Data.Get(l - 1)
+ p.QueueMessage(ethwire.NewMessage(ethwire.MsgNotInChainTy, lastHash))
+ }
+ case ethwire.MsgNotInChainTy:
+ log.Println("Not in chain, not yet implemented")
+ // TODO
+ // Unofficial but fun nonetheless
+ case ethwire.MsgTalkTy:
+ log.Printf("%v says: %s\n", p.conn.RemoteAddr(), msg.Data.Get(0).AsString())
}
}