@@ -59,8 +59,7 @@ type peer struct {
5959 id string
6060
6161 * p2p.Peer
62- rw p2p.MsgReadWriter
63- pairRw p2p.MsgReadWriter
62+ rw p2p.MsgReadWriter
6463
6564 version int // Protocol version negotiated
6665 forkDrop * time.Timer // Timed connection dropper if forks aren't validated in time
@@ -262,59 +261,35 @@ func (p *peer) SendNewBlock(block *types.Block, td *big.Int) error {
262261 }
263262
264263 p .knownBlocks .Add (block .Hash ())
265- if p .pairRw != nil {
266- return p2p .Send (p .pairRw , NewBlockMsg , []interface {}{block , td })
267- } else {
268- return p2p .Send (p .rw , NewBlockMsg , []interface {}{block , td })
269- }
264+ return p2p .Send (p .rw , NewBlockMsg , []interface {}{block , td })
270265}
271266
272267// SendBlockHeaders sends a batch of block headers to the remote peer.
273268func (p * peer ) SendBlockHeaders (headers []* types.Header ) error {
274- if p .pairRw != nil {
275- return p2p .Send (p .pairRw , BlockHeadersMsg , headers )
276- } else {
277- return p2p .Send (p .rw , BlockHeadersMsg , headers )
278- }
269+ return p2p .Send (p .rw , BlockHeadersMsg , headers )
279270}
280271
281272// SendBlockBodies sends a batch of block contents to the remote peer.
282273func (p * peer ) SendBlockBodies (bodies []* blockBody ) error {
283- if p .pairRw != nil {
284- return p2p .Send (p .pairRw , BlockBodiesMsg , blockBodiesData (bodies ))
285- } else {
286- return p2p .Send (p .rw , BlockBodiesMsg , blockBodiesData (bodies ))
287- }
274+ return p2p .Send (p .rw , BlockBodiesMsg , blockBodiesData (bodies ))
288275}
289276
290277// SendBlockBodiesRLP sends a batch of block contents to the remote peer from
291278// an already RLP encoded format.
292279func (p * peer ) SendBlockBodiesRLP (bodies []rlp.RawValue ) error {
293- if p .pairRw != nil {
294- return p2p .Send (p .pairRw , BlockBodiesMsg , bodies )
295- } else {
296- return p2p .Send (p .rw , BlockBodiesMsg , bodies )
297- }
280+ return p2p .Send (p .rw , BlockBodiesMsg , bodies )
298281}
299282
300283// SendNodeDataRLP sends a batch of arbitrary internal data, corresponding to the
301284// hashes requested.
302285func (p * peer ) SendNodeData (data [][]byte ) error {
303- if p .pairRw != nil {
304- return p2p .Send (p .pairRw , NodeDataMsg , data )
305- } else {
306- return p2p .Send (p .rw , NodeDataMsg , data )
307- }
286+ return p2p .Send (p .rw , NodeDataMsg , data )
308287}
309288
310289// SendReceiptsRLP sends a batch of transaction receipts, corresponding to the
311290// ones requested from an already RLP encoded format.
312291func (p * peer ) SendReceiptsRLP (receipts []rlp.RawValue ) error {
313- if p .pairRw != nil {
314- return p2p .Send (p .pairRw , ReceiptsMsg , receipts )
315- } else {
316- return p2p .Send (p .rw , ReceiptsMsg , receipts )
317- }
292+ return p2p .Send (p .rw , ReceiptsMsg , receipts )
318293}
319294
320295func (p * peer ) SendVote (vote * types.Vote ) error {
@@ -323,11 +298,7 @@ func (p *peer) SendVote(vote *types.Vote) error {
323298 }
324299
325300 p .knownVote .Add (vote .Hash ())
326- if p .pairRw != nil {
327- return p2p .Send (p .pairRw , VoteMsg , vote )
328- } else {
329- return p2p .Send (p .rw , VoteMsg , vote )
330- }
301+ return p2p .Send (p .rw , VoteMsg , vote )
331302}
332303
333304/*
@@ -341,11 +312,7 @@ func (p *peer) SendTimeout(timeout *types.Timeout) error {
341312 }
342313
343314 p .knownTimeout .Add (timeout .Hash ())
344- if p .pairRw != nil {
345- return p2p .Send (p .pairRw , TimeoutMsg , timeout )
346- } else {
347- return p2p .Send (p .rw , TimeoutMsg , timeout )
348- }
315+ return p2p .Send (p .rw , TimeoutMsg , timeout )
349316}
350317
351318/*
@@ -359,11 +326,7 @@ func (p *peer) SendSyncInfo(syncInfo *types.SyncInfo) error {
359326 }
360327
361328 p .knownSyncInfo .Add (syncInfo .Hash ())
362- if p .pairRw != nil {
363- return p2p .Send (p .pairRw , SyncInfoMsg , syncInfo )
364- } else {
365- return p2p .Send (p .rw , SyncInfoMsg , syncInfo )
366- }
329+ return p2p .Send (p .rw , SyncInfoMsg , syncInfo )
367330}
368331
369332/*
@@ -376,65 +339,41 @@ func (p *peer) AsyncSendSyncInfo() {
376339// single header. It is used solely by the fetcher.
377340func (p * peer ) RequestOneHeader (hash common.Hash ) error {
378341 p .Log ().Debug ("Fetching single header" , "hash" , hash )
379- if p .pairRw != nil {
380- return p2p .Send (p .pairRw , GetBlockHeadersMsg , & getBlockHeadersData {Origin : hashOrNumber {Hash : hash }, Amount : uint64 (1 ), Skip : uint64 (0 ), Reverse : false })
381- } else {
382- return p2p .Send (p .rw , GetBlockHeadersMsg , & getBlockHeadersData {Origin : hashOrNumber {Hash : hash }, Amount : uint64 (1 ), Skip : uint64 (0 ), Reverse : false })
383- }
342+ return p2p .Send (p .rw , GetBlockHeadersMsg , & getBlockHeadersData {Origin : hashOrNumber {Hash : hash }, Amount : uint64 (1 ), Skip : uint64 (0 ), Reverse : false })
384343}
385344
386345// RequestHeadersByHash fetches a batch of blocks' headers corresponding to the
387346// specified header query, based on the hash of an origin block.
388347func (p * peer ) RequestHeadersByHash (origin common.Hash , amount int , skip int , reverse bool ) error {
389348 p .Log ().Debug ("Fetching batch of headers" , "count" , amount , "fromhash" , origin , "skip" , skip , "reverse" , reverse )
390- if p .pairRw != nil {
391- return p2p .Send (p .pairRw , GetBlockHeadersMsg , & getBlockHeadersData {Origin : hashOrNumber {Hash : origin }, Amount : uint64 (amount ), Skip : uint64 (skip ), Reverse : reverse })
392- } else {
393- return p2p .Send (p .rw , GetBlockHeadersMsg , & getBlockHeadersData {Origin : hashOrNumber {Hash : origin }, Amount : uint64 (amount ), Skip : uint64 (skip ), Reverse : reverse })
394- }
349+ return p2p .Send (p .rw , GetBlockHeadersMsg , & getBlockHeadersData {Origin : hashOrNumber {Hash : origin }, Amount : uint64 (amount ), Skip : uint64 (skip ), Reverse : reverse })
395350}
396351
397352// RequestHeadersByNumber fetches a batch of blocks' headers corresponding to the
398353// specified header query, based on the number of an origin block.
399354func (p * peer ) RequestHeadersByNumber (origin uint64 , amount int , skip int , reverse bool ) error {
400355 p .Log ().Debug ("Fetching batch of headers" , "count" , amount , "fromnum" , origin , "skip" , skip , "reverse" , reverse )
401- if p .pairRw != nil {
402- return p2p .Send (p .pairRw , GetBlockHeadersMsg , & getBlockHeadersData {Origin : hashOrNumber {Number : origin }, Amount : uint64 (amount ), Skip : uint64 (skip ), Reverse : reverse })
403- } else {
404- return p2p .Send (p .rw , GetBlockHeadersMsg , & getBlockHeadersData {Origin : hashOrNumber {Number : origin }, Amount : uint64 (amount ), Skip : uint64 (skip ), Reverse : reverse })
405- }
356+ return p2p .Send (p .rw , GetBlockHeadersMsg , & getBlockHeadersData {Origin : hashOrNumber {Number : origin }, Amount : uint64 (amount ), Skip : uint64 (skip ), Reverse : reverse })
406357}
407358
408359// RequestBodies fetches a batch of blocks' bodies corresponding to the hashes
409360// specified.
410361func (p * peer ) RequestBodies (hashes []common.Hash ) error {
411362 p .Log ().Debug ("Fetching batch of block bodies" , "count" , len (hashes ))
412- if p .pairRw != nil {
413- return p2p .Send (p .pairRw , GetBlockBodiesMsg , hashes )
414- } else {
415- return p2p .Send (p .rw , GetBlockBodiesMsg , hashes )
416- }
363+ return p2p .Send (p .rw , GetBlockBodiesMsg , hashes )
417364}
418365
419366// RequestNodeData fetches a batch of arbitrary data from a node's known state
420367// data, corresponding to the specified hashes.
421368func (p * peer ) RequestNodeData (hashes []common.Hash ) error {
422369 p .Log ().Debug ("Fetching batch of state data" , "count" , len (hashes ))
423- if p .pairRw != nil {
424- return p2p .Send (p .pairRw , GetNodeDataMsg , hashes )
425- } else {
426- return p2p .Send (p .rw , GetNodeDataMsg , hashes )
427- }
370+ return p2p .Send (p .rw , GetNodeDataMsg , hashes )
428371}
429372
430373// RequestReceipts fetches a batch of transaction receipts from a remote node.
431374func (p * peer ) RequestReceipts (hashes []common.Hash ) error {
432375 p .Log ().Debug ("Fetching batch of receipts" , "count" , len (hashes ))
433- if p .pairRw != nil {
434- return p2p .Send (p .pairRw , GetReceiptsMsg , hashes )
435- } else {
436- return p2p .Send (p .rw , GetReceiptsMsg , hashes )
437- }
376+ return p2p .Send (p .rw , GetReceiptsMsg , hashes )
438377}
439378
440379// Handshake executes the eth protocol handshake, negotiating version number,
@@ -530,14 +469,8 @@ func (ps *peerSet) Register(p *peer) error {
530469 if ps .closed {
531470 return errClosed
532471 }
533- if existPeer , ok := ps .peers [p .id ]; ok {
534- if existPeer .pairRw != nil {
535- return errAlreadyRegistered
536- }
537- existPeer .SetPairPeer (p .Peer )
538- existPeer .pairRw = p .rw
539- p .SetPairPeer (existPeer .Peer )
540- return p2p .ErrAddPairPeer
472+ if _ , ok := ps .peers [p .id ]; ok {
473+ return errAlreadyRegistered
541474 }
542475 ps .peers [p .id ] = p
543476 return nil
0 commit comments