mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 20:56:42 +00:00
rlp encode hack
This commit is contained in:
parent
9c5b1dbf0c
commit
76c6b7546f
3 changed files with 21 additions and 11 deletions
|
|
@ -143,6 +143,7 @@ func (self *NetStore) addRetrieveRequest(req *retrieveRequestMsgData) {
|
|||
defer self.lock.Unlock()
|
||||
|
||||
chunk := self.get(req.Key)
|
||||
req.timeout = time.Now().Add(10 * time.Second)
|
||||
|
||||
send, timeout := self.strategyUpdateRequest(chunk.req, req) // may change req status
|
||||
|
||||
|
|
@ -165,7 +166,7 @@ func (self *NetStore) startSearch(chunk *Chunk, id int64, timeout time.Time) {
|
|||
req := &retrieveRequestMsgData{
|
||||
Key: chunk.Key,
|
||||
Id: uint64(id),
|
||||
Timeout: timeout,
|
||||
timeout: timeout,
|
||||
}
|
||||
for _, peer := range peers {
|
||||
peer.retrieve(req)
|
||||
|
|
@ -224,7 +225,7 @@ func (self *NetStore) propagateResponse(chunk *Chunk) {
|
|||
Id: uint64(id),
|
||||
}
|
||||
for _, req := range requesters {
|
||||
if req.Timeout.After(time.Now()) {
|
||||
if req.timeout.After(time.Now()) {
|
||||
go req.peer.store(msg)
|
||||
counter--
|
||||
if counter <= 0 {
|
||||
|
|
@ -241,7 +242,7 @@ func (self *NetStore) deliver(req *retrieveRequestMsgData, chunk *Chunk) {
|
|||
Id: req.Id,
|
||||
Data: chunk.Data,
|
||||
Size: uint64(chunk.Size),
|
||||
RequestTimeout: req.Timeout, //
|
||||
RequestTimeout: req.timeout, //
|
||||
// StorageTimeout time.Time // expiry of content
|
||||
// Metadata metaData
|
||||
}
|
||||
|
|
@ -273,8 +274,8 @@ func (self *NetStore) peers(req *retrieveRequestMsgData, chunk *Chunk, timeout t
|
|||
|
||||
func (self *NetStore) searchTimeout(rs *requestStatus, req *retrieveRequestMsgData) (timeout *time.Time) {
|
||||
t := time.Now().Add(searchTimeout)
|
||||
if req.Timeout.Before(t) {
|
||||
return &req.Timeout
|
||||
if req.timeout.Before(t) {
|
||||
return &req.timeout
|
||||
} else {
|
||||
return &t
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,10 +95,10 @@ It is unclear if a retrieval request with an empty target is the same as a self
|
|||
type retrieveRequestMsgData struct {
|
||||
Key Key
|
||||
// optional
|
||||
Id uint64 //
|
||||
MaxSize uint64 // maximum size of delivery accepted
|
||||
Timeout time.Time //
|
||||
Metadata metaData //
|
||||
Id uint64 //
|
||||
MaxSize uint64 // maximum size of delivery accepted
|
||||
timeout time.Time //
|
||||
//Metadata metaData //
|
||||
//
|
||||
peer peer
|
||||
}
|
||||
|
|
@ -279,7 +279,10 @@ func (self *bzzProtocol) handleStatus() (err error) {
|
|||
// outgoing messages
|
||||
func (self *bzzProtocol) retrieve(req *retrieveRequestMsgData) {
|
||||
dpaLogger.Warnf("Request message: %#v", req)
|
||||
p2p.EncodeMsg(self.rw, retrieveRequestMsg, req)
|
||||
err := p2p.EncodeMsg(self.rw, retrieveRequestMsg, req.Key, req.Id, req.MaxSize)
|
||||
if err != nil {
|
||||
dpaLogger.Errorf("EncodeMsg error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (self *bzzProtocol) store(req *storeRequestMsgData) {
|
||||
|
|
|
|||
|
|
@ -102,12 +102,18 @@ func writeMsg(w io.Writer, msg Msg) error {
|
|||
copy(start, magicToken)
|
||||
binary.BigEndian.PutUint32(start[4:], payloadLen)
|
||||
|
||||
srvlog.Warnf("Sending message:")
|
||||
|
||||
for _, b := range [][]byte{start, listhdr, code} {
|
||||
srvlog.Warnf(" %x", b)
|
||||
if _, err := w.Write(b); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
_, err := io.CopyN(w, msg.Payload, int64(msg.Size))
|
||||
b := make([]byte, msg.Size)
|
||||
msg.Payload.Read(b)
|
||||
srvlog.Warnf(" %x", b)
|
||||
_, err := w.Write(b)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue