|
|
@ -168,7 +168,7 @@ func (b *Bzz) APIs() []rpc.API { |
|
|
|
func (b *Bzz) RunProtocol(spec *protocols.Spec, run func(*BzzPeer) error) func(*p2p.Peer, p2p.MsgReadWriter) error { |
|
|
|
func (b *Bzz) RunProtocol(spec *protocols.Spec, run func(*BzzPeer) error) func(*p2p.Peer, p2p.MsgReadWriter) error { |
|
|
|
return func(p *p2p.Peer, rw p2p.MsgReadWriter) error { |
|
|
|
return func(p *p2p.Peer, rw p2p.MsgReadWriter) error { |
|
|
|
// wait for the bzz protocol to perform the handshake
|
|
|
|
// wait for the bzz protocol to perform the handshake
|
|
|
|
handshake, _ := b.GetHandshake(p.ID()) |
|
|
|
handshake, _ := b.GetOrCreateHandshake(p.ID()) |
|
|
|
defer b.removeHandshake(p.ID()) |
|
|
|
defer b.removeHandshake(p.ID()) |
|
|
|
select { |
|
|
|
select { |
|
|
|
case <-handshake.done: |
|
|
|
case <-handshake.done: |
|
|
@ -213,7 +213,7 @@ func (b *Bzz) performHandshake(p *protocols.Peer, handshake *HandshakeMsg) error |
|
|
|
// runBzz is the p2p protocol run function for the bzz base protocol
|
|
|
|
// runBzz is the p2p protocol run function for the bzz base protocol
|
|
|
|
// that negotiates the bzz handshake
|
|
|
|
// that negotiates the bzz handshake
|
|
|
|
func (b *Bzz) runBzz(p *p2p.Peer, rw p2p.MsgReadWriter) error { |
|
|
|
func (b *Bzz) runBzz(p *p2p.Peer, rw p2p.MsgReadWriter) error { |
|
|
|
handshake, _ := b.GetHandshake(p.ID()) |
|
|
|
handshake, _ := b.GetOrCreateHandshake(p.ID()) |
|
|
|
if !<-handshake.init { |
|
|
|
if !<-handshake.init { |
|
|
|
return fmt.Errorf("%08x: bzz already started on peer %08x", b.localAddr.Over()[:4], p.ID().Bytes()[:4]) |
|
|
|
return fmt.Errorf("%08x: bzz already started on peer %08x", b.localAddr.Over()[:4], p.ID().Bytes()[:4]) |
|
|
|
} |
|
|
|
} |
|
|
@ -303,7 +303,7 @@ func (b *Bzz) removeHandshake(peerID enode.ID) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GetHandshake returns the bzz handhake that the remote peer with peerID sent
|
|
|
|
// GetHandshake returns the bzz handhake that the remote peer with peerID sent
|
|
|
|
func (b *Bzz) GetHandshake(peerID enode.ID) (*HandshakeMsg, bool) { |
|
|
|
func (b *Bzz) GetOrCreateHandshake(peerID enode.ID) (*HandshakeMsg, bool) { |
|
|
|
b.mtx.Lock() |
|
|
|
b.mtx.Lock() |
|
|
|
defer b.mtx.Unlock() |
|
|
|
defer b.mtx.Unlock() |
|
|
|
handshake, found := b.handshakes[peerID] |
|
|
|
handshake, found := b.handshakes[peerID] |
|
|
|