aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/peer.go
diff options
context:
space:
mode:
authorzelig <viktor.tron@gmail.com>2015-01-18 15:59:54 +0800
committerFelix Lange <fjl@twurst.com>2015-02-06 07:00:34 +0800
commitc8a8aa0d43336491f6aa264467968e06b489d34c (patch)
tree7a22de1e289ac8aef57089d4cc4412debbee213e /p2p/peer.go
parent6b5f25802e73056702b743e0cab284cef49381ad (diff)
downloadgo-tangerine-c8a8aa0d43336491f6aa264467968e06b489d34c.tar
go-tangerine-c8a8aa0d43336491f6aa264467968e06b489d34c.tar.gz
go-tangerine-c8a8aa0d43336491f6aa264467968e06b489d34c.tar.bz2
go-tangerine-c8a8aa0d43336491f6aa264467968e06b489d34c.tar.lz
go-tangerine-c8a8aa0d43336491f6aa264467968e06b489d34c.tar.xz
go-tangerine-c8a8aa0d43336491f6aa264467968e06b489d34c.tar.zst
go-tangerine-c8a8aa0d43336491f6aa264467968e06b489d34c.zip
initial hook for crypto handshake (void, off by default)
Diffstat (limited to 'p2p/peer.go')
-rw-r--r--p2p/peer.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/p2p/peer.go b/p2p/peer.go
index 2380a3285..886b95a80 100644
--- a/p2p/peer.go
+++ b/p2p/peer.go
@@ -70,6 +70,7 @@ type Peer struct {
// These fields maintain the running protocols.
protocols []Protocol
runBaseProtocol bool // for testing
+ cryptoHandshake bool // for testing
runlock sync.RWMutex // protects running
running map[string]*proto
@@ -141,6 +142,20 @@ func (p *Peer) Identity() ClientIdentity {
return p.identity
}
+func (self *Peer) Pubkey() (pubkey []byte) {
+ self.infolock.Lock()
+ defer self.infolock.Unlock()
+ switch {
+ case self.identity != nil:
+ pubkey = self.identity.Pubkey()
+ case self.dialAddr != nil:
+ pubkey = self.dialAddr.Pubkey
+ case self.listenAddr != nil:
+ pubkey = self.listenAddr.Pubkey
+ }
+ return
+}
+
// Caps returns the capabilities (supported subprotocols) of the remote peer.
func (p *Peer) Caps() []Cap {
p.infolock.Lock()
@@ -207,6 +222,12 @@ func (p *Peer) loop() (reason DiscReason, err error) {
defer close(p.closed)
defer p.conn.Close()
+ if p.cryptoHandshake {
+ if err := p.handleCryptoHandshake(); err != nil {
+ return DiscProtocolError, err // no graceful disconnect
+ }
+ }
+
// read loop
readMsg := make(chan Msg)
readErr := make(chan error)
@@ -307,6 +328,11 @@ func (p *Peer) dispatch(msg Msg, protoDone chan struct{}) (wait bool, err error)
return wait, nil
}
+func (p *Peer) handleCryptoHandshake() (err error) {
+
+ return nil
+}
+
func (p *Peer) startBaseProtocol() {
p.runlock.Lock()
defer p.runlock.Unlock()