@@ -141,7 +141,7 @@ type PeerSet struct {
141141 // TODO: this will be useful for reserved only mode
142142 // this is for future purpose if reserved-only flag is enabled (#1888).
143143 isReservedOnly bool
144- resultMsgCh chan interface {}
144+ resultMsgCh chan Message
145145 // time when the PeerSet was created.
146146 created time.Time
147147 // last time when we updated the reputations of connected nodes.
@@ -183,6 +183,8 @@ func NewConfigSet(in, out uint32, reservedOnly bool, allocTime time.Duration) *C
183183 }
184184
185185 return & ConfigSet {
186+ // Why are we using an array of config in the set, when we are
187+ // using just one config
186188 Set : []* config {set },
187189 }
188190}
@@ -228,8 +230,8 @@ func reputationTick(reput Reputation) Reputation {
228230 return reput .sub (diff )
229231}
230232
231- // updateTime updates the value of latestTimeUpdate and performs all the updates that happen
232- // over time, such as Reputation increases for staying connected.
233+ // updateTime updates the value of latestTimeUpdate and performs all the updates that
234+ // happen over time, such as Reputation increases for staying connected.
233235func (ps * PeerSet ) updateTime () error {
234236 currTime := time .Now ()
235237 // identify the time difference between current time and last update time for peer reputation in seconds.
@@ -282,8 +284,8 @@ func (ps *PeerSet) updateTime() error {
282284}
283285
284286// reportPeer on report ReputationChange of the peer based on its behaviour,
285- // if the updated Reputation is below BannedThresholdValue then, this node need to be disconnected
286- // and a drop message for the peer is sent in order to disconnect.
287+ // if the updated Reputation is below BannedThresholdValue then, this node need to
288+ // be disconnected and a drop message for the peer is sent in order to disconnect.
287289func (ps * PeerSet ) reportPeer (change ReputationChange , peers ... peer.ID ) error {
288290 // we want reputations to be up-to-date before adjusting them.
289291 if err := ps .updateTime (); err != nil {
@@ -516,8 +518,9 @@ func (ps *PeerSet) removePeer(setID int, peers ...peer.ID) error {
516518 return nil
517519}
518520
519- // incoming indicates that we have received an incoming connection. Must be answered either with
520- // a corresponding `Accept` or `Reject`, except if we were already connected to this peer.
521+ // incoming indicates that we have received an incoming connection. Must be answered
522+ // either with a corresponding `Accept` or `Reject`, except if we were already
523+ // connected to this peer.
521524func (ps * PeerSet ) incoming (setID int , peers ... peer.ID ) error {
522525 if err := ps .updateTime (); err != nil {
523526 return err
@@ -527,7 +530,11 @@ func (ps *PeerSet) incoming(setID int, peers ...peer.ID) error {
527530 for _ , pid := range peers {
528531 if ps .isReservedOnly {
529532 if _ , ok := ps .reservedNode [pid ]; ! ok {
530- ps .resultMsgCh <- Message {Status : Reject }
533+ ps .resultMsgCh <- Message {
534+ Status : Reject ,
535+ setID : uint64 (setID ),
536+ PeerID : pid ,
537+ }
531538 continue
532539 }
533540 }
@@ -546,11 +553,24 @@ func (ps *PeerSet) incoming(setID int, peers ...peer.ID) error {
546553 p := state .nodes [pid ]
547554 switch {
548555 case p .getReputation () < BannedThresholdValue :
549- ps .resultMsgCh <- Message {Status : Reject }
556+ ps .resultMsgCh <- Message {
557+ Status : Reject ,
558+ setID : uint64 (setID ),
559+ PeerID : pid ,
560+ }
550561 case state .tryAcceptIncoming (setID , pid ) != nil :
551- ps .resultMsgCh <- Message {Status : Reject }
562+ ps .resultMsgCh <- Message {
563+ Status : Reject ,
564+ setID : uint64 (setID ),
565+ PeerID : pid ,
566+ }
552567 default :
553- ps .resultMsgCh <- Message {Status : Accept }
568+ logger .Debugf ("incoming connection accepted from peer %s" , pid )
569+ ps .resultMsgCh <- Message {
570+ Status : Accept ,
571+ setID : uint64 (setID ),
572+ PeerID : pid ,
573+ }
554574 }
555575 }
556576
@@ -593,6 +613,7 @@ func (ps *PeerSet) disconnect(setIdx int, reason DropReason, peers ...peer.ID) e
593613 }
594614 ps .resultMsgCh <- Message {
595615 Status : Drop ,
616+ setID : uint64 (setIdx ),
596617 PeerID : pid ,
597618 }
598619
@@ -610,7 +631,7 @@ func (ps *PeerSet) disconnect(setIdx int, reason DropReason, peers ...peer.ID) e
610631// start handles all the action for the peerSet.
611632func (ps * PeerSet ) start (aq chan action ) {
612633 ps .actionQueue = aq
613- ps .resultMsgCh = make (chan interface {} , msgChanSize )
634+ ps .resultMsgCh = make (chan Message , msgChanSize )
614635 go ps .doWork ()
615636}
616637
0 commit comments