mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 20:26:41 +00:00
bzz msg encode fixed
This commit is contained in:
parent
5698fe9859
commit
dbca2238d4
3 changed files with 25 additions and 22 deletions
|
|
@ -345,6 +345,10 @@ func (self *TreeChunker) join(depth int, treeSize int64, key Key, chunkC chan *C
|
||||||
case <-chunk.C: // bells are ringing, data have been delivered
|
case <-chunk.C: // bells are ringing, data have been delivered
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if data == nil {
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
|
||||||
// calculate depth and max treeSize
|
// calculate depth and max treeSize
|
||||||
var depth int
|
var depth int
|
||||||
var treeSize int64 = self.hashSize
|
var treeSize int64 = self.hashSize
|
||||||
|
|
|
||||||
|
|
@ -224,25 +224,24 @@ func (self *bzzProtocol) handle() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *bzzProtocol) statusMsg() p2p.Msg {
|
func (self *bzzProtocol) handleStatus() (err error) {
|
||||||
|
|
||||||
return p2p.NewMsg(statusMsg,
|
|
||||||
uint32(Version),
|
|
||||||
uint32(NetworkId),
|
|
||||||
"honey",
|
|
||||||
[]p2p.Cap{},
|
|
||||||
strategy,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (self *bzzProtocol) handleStatus() error {
|
|
||||||
// send precanned status message
|
// send precanned status message
|
||||||
if err := self.rw.WriteMsg(self.statusMsg()); err != nil {
|
handshake := &statusMsgData{
|
||||||
|
Version: uint64(Version),
|
||||||
|
ID: "honey",
|
||||||
|
NodeID: self.peer.OurPubkey(),
|
||||||
|
NetworkId: uint64(NetworkId),
|
||||||
|
Caps: []p2p.Cap{},
|
||||||
|
}
|
||||||
|
|
||||||
|
//if err := self.rw.WriteMsg(self.statusMsg()); err != nil {
|
||||||
|
if err = p2p.EncodeMsg(self.rw, statusMsg, handshake); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// read and handle remote status
|
// read and handle remote status
|
||||||
msg, err := self.rw.ReadMsg()
|
var msg p2p.Msg
|
||||||
|
msg, err = self.rw.ReadMsg()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -270,13 +269,7 @@ func (self *bzzProtocol) handleStatus() error {
|
||||||
|
|
||||||
self.peer.Infof("Peer is [bzz] capable (%d/%d)\n", status.Version, status.NetworkId)
|
self.peer.Infof("Peer is [bzz] capable (%d/%d)\n", status.Version, status.NetworkId)
|
||||||
|
|
||||||
req := &peersMsgData{
|
self.hive.addPeer(peer{bzzProtocol: self, pubkey: status.NodeID})
|
||||||
// Peers: []*peerAddr{self.peer.Address()}, // not implemented in p2p, should be the same as node discovery cademlia
|
|
||||||
// Key: nil,
|
|
||||||
peer: peer{bzzProtocol: self, pubkey: status.NodeID},
|
|
||||||
}
|
|
||||||
|
|
||||||
self.hive.addPeers(req)
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ type Peer struct {
|
||||||
// Use them to display messages related to the peer.
|
// Use them to display messages related to the peer.
|
||||||
*logger.Logger
|
*logger.Logger
|
||||||
|
|
||||||
infolock sync.Mutex
|
infolock sync.RWMutex
|
||||||
identity ClientIdentity
|
identity ClientIdentity
|
||||||
caps []Cap
|
caps []Cap
|
||||||
listenAddr *peerAddr // what remote peer is listening on
|
listenAddr *peerAddr // what remote peer is listening on
|
||||||
|
|
@ -132,6 +132,12 @@ func newPeer(conn net.Conn, protocols []Protocol, dialAddr *peerAddr) *Peer {
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *Peer) OurPubkey() (pubkey []byte) {
|
||||||
|
self.infolock.RLock()
|
||||||
|
defer self.infolock.RUnlock()
|
||||||
|
return self.ourID.Pubkey()
|
||||||
|
}
|
||||||
|
|
||||||
// Identity returns the client identity of the remote peer. The
|
// Identity returns the client identity of the remote peer. The
|
||||||
// identity can be nil if the peer has not yet completed the
|
// identity can be nil if the peer has not yet completed the
|
||||||
// handshake.
|
// handshake.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue