)
type worseConnInput struct {
+ BadDirection bool
Useful bool
LastHelpful time.Time
CompletedHandshake time.Time
me.getPeerPriorityOnce.Do(me.doGetPeerPriority)
}
-func worseConnInputFromPeer(p *Peer) worseConnInput {
+type worseConnLensOpts struct {
+ incomingIsBad, outgoingIsBad bool
+}
+
+func worseConnInputFromPeer(p *PeerConn, opts worseConnLensOpts) worseConnInput {
ret := worseConnInput{
Useful: p.useful(),
LastHelpful: p.lastHelpful(),
Pointer: uintptr(unsafe.Pointer(p)),
GetPeerPriority: p.peerPriority,
}
+ if opts.incomingIsBad && !p.outgoing {
+ ret.BadDirection = true
+ } else if opts.outgoingIsBad && p.outgoing {
+ ret.BadDirection = true
+ }
return ret
}
-func worseConn(_l, _r *Peer) bool {
- // TODO: Use generics for ptr to
- l := worseConnInputFromPeer(_l)
- r := worseConnInputFromPeer(_r)
- return l.Less(&r)
-}
-
func (l *worseConnInput) Less(r *worseConnInput) bool {
less, ok := multiless.New().Bool(
+ r.BadDirection, l.BadDirection).Bool(
l.Useful, r.Useful).CmpInt64(
l.LastHelpful.Sub(r.LastHelpful).Nanoseconds()).CmpInt64(
l.CompletedHandshake.Sub(r.CompletedHandshake).Nanoseconds()).LazySameLess(
keys []worseConnInput
}
-func (me *worseConnSlice) initKeys() {
+func (me *worseConnSlice) initKeys(opts worseConnLensOpts) {
me.keys = make([]worseConnInput, len(me.conns))
for i, c := range me.conns {
- me.keys[i] = worseConnInputFromPeer(&c.Peer)
+ me.keys[i] = worseConnInputFromPeer(c, opts)
}
}