Skip to content

Commit c8a8aa0

Browse files
zeligfjl
authored andcommitted
initial hook for crypto handshake (void, off by default)
1 parent 6b5f258 commit c8a8aa0

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

‎p2p/peer.go‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ type Peer struct {
7070
// These fields maintain the running protocols.
7171
protocols []Protocol
7272
runBaseProtocol bool // for testing
73+
cryptoHandshake bool // for testing
7374

7475
runlock sync.RWMutex // protects running
7576
running map[string]*proto
@@ -141,6 +142,20 @@ func (p *Peer) Identity() ClientIdentity {
141142
return p.identity
142143
}
143144

145+
func (self *Peer) Pubkey() (pubkey []byte) {
146+
self.infolock.Lock()
147+
defer self.infolock.Unlock()
148+
switch {
149+
case self.identity != nil:
150+
pubkey = self.identity.Pubkey()
151+
case self.dialAddr != nil:
152+
pubkey = self.dialAddr.Pubkey
153+
case self.listenAddr != nil:
154+
pubkey = self.listenAddr.Pubkey
155+
}
156+
return
157+
}
158+
144159
// Caps returns the capabilities (supported subprotocols) of the remote peer.
145160
func (p *Peer) Caps() []Cap {
146161
p.infolock.Lock()
@@ -207,6 +222,12 @@ func (p *Peer) loop() (reason DiscReason, err error) {
207222
defer close(p.closed)
208223
defer p.conn.Close()
209224

225+
if p.cryptoHandshake {
226+
if err := p.handleCryptoHandshake(); err != nil {
227+
return DiscProtocolError, err // no graceful disconnect
228+
}
229+
}
230+
210231
// read loop
211232
readMsg := make(chan Msg)
212233
readErr := make(chan error)
@@ -307,6 +328,11 @@ func (p *Peer) dispatch(msg Msg, protoDone chan struct{}) (wait bool, err error)
307328
return wait, nil
308329
}
309330

331+
func (p *Peer) handleCryptoHandshake() (err error) {
332+
333+
return nil
334+
}
335+
310336
func (p *Peer) startBaseProtocol() {
311337
p.runlock.Lock()
312338
defer p.runlock.Unlock()

0 commit comments

Comments
 (0)