Skip to content
This repository has been archived by the owner on Jul 6, 2018. It is now read-only.

Pex reactor fixes #9 #10

Merged
merged 22 commits into from
Apr 20, 2017
Merged

Pex reactor fixes #9 #10

merged 22 commits into from
Apr 20, 2017

Conversation

melekes
Copy link
Contributor

@melekes melekes commented Jan 11, 2017

Started to work on pex reactor issues (Refs #9).

What's done / left:

@melekes melekes force-pushed the pex-reactor-fixes-#9 branch 2 times, most recently from e106259 to c0ca201 Compare January 12, 2017 18:31
@melekes
Copy link
Contributor Author

melekes commented Jan 12, 2017

I've looked into addrmanager and there were no significant changes since mid-2015.

Still, I liked that they choose address based on distance https://github.com/btcsuite/btcd/blob/master/addrmgr/addrmanager.go#L1046 (we choose randomly).


// Try to pick numToDial addresses to dial.
// TODO: improve logic.
Copy link
Contributor Author

@melekes melekes Jan 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jaekwon what did you have in mind? something concrete? I've managed to get rid of alreadyConnected flag by using addrbook old group. I will try to think about something else for the time being.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand how alreadyConnected can be removed. An address's membership in addrbook (old or new) has no bearing on whether the address is already connected.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we mark the peer good after successful connection and pick addresses with the bias = 100% (always from new buckets), we don't need to check alreadyConnected (since all the peers with whom we already have a connection will be in the old buckets) b898bc3

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but that's not what we want to do.

Old bucket / New bucket are arbitrary categories to denote whether an address is vetted or not, and this needs to be determined over time via a heuristic that we haven't perfected yet, or, perhaps is manually edited by the node operator. It should not be used to compute what addresses are already connected or not.

The old code may have been buggy, but these modifications are definitely bad.

Copy link
Contributor

@jaekwon jaekwon Apr 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we mark the peer good after successful connection...

Basically, we need to work harder on our good-peer/bad-peer marking. What we're currently doing in terms of marking good/bad peers is just a placeholder.
It should not be the case that an address becomes old/vetted upon a single successful connection. That's not the intent of the old/new system.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for explaining this to me. It wasn't clear to me before. I will revert the change and add a comment to the source code so we could refer to it in the future.

pex_reactor.go Outdated
func (r *PEXReactor) RemovePeer(p *Peer, reason interface{}) {
addr := NewNetAddressString(p.ListenAddr)
// addr will be ejected from the book
r.book.MarkBad(addr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will need to depend on the reason. If the peer just goes offline, we probably don't want to remove them

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure?

NOTE: The peer will be proposed to us by other peers (PexAddrsMessage) and we will add it again upon successful connection.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if the peer actually went offline, wont all the other peers remove him too? Granted the PEX should enable everyone to find him when he next connects.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Peer will need to send first requests to others by itself (he will have an addrbook or the seeds). Is it bad?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I guess it's ok. Down the road I think we will want to preserve "MarkBad" for peers that actually misbehave.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds right. I will add RemoveAddress to addrbook then.

@ebuchman
Copy link
Contributor

Looks good. I think limiting to eg 1000 msg/hour is fine for now. Maybe down the road we want to keep track of the quality of peer messages so if peerA keeps telling us about peers we can't connect to then maybe we should care less about peerA. But I don't think that kind of complexity is priority right now

@melekes
Copy link
Contributor Author

melekes commented Jan 17, 2017

Maybe down the road we want to keep track of the quality of peer messages so if peerA keeps telling us about peers we can't connect to then maybe we should care less about peerA. But I don't think that kind of complexity is priority right now

OK. I will add the comment

melekes added a commit that referenced this pull request Jan 20, 2017
pex_reactor.go Outdated
// will remove him too. The peer will need to send first requests to others by
// himself (he will have an addrbook or the seeds).
func (r *PEXReactor) RemovePeer(p *Peer, reason interface{}) {
addr := NewNetAddressString(p.ListenAddr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AddPeer/RemovePeer are just housekeeping methods, we shouldn't remove a peer from the addrbook just because they got disconnected.

We could rename AddPeer/RemovePeer to "OnPeerConnect" and "OnPeerDisconnect". If we aren't keeping track of local temp data for each peer here, then we don't have to do anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought if we add the peer to the book upon connection (AddPeer), we should respectively remove him upon losing the connection (RemovePeer). It just sounds logical. In addition, the peer will reach us once he up again (or network healed; though, not sure about the network case, need to test it with iptables). #10 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will revert this too.

melekes added a commit that referenced this pull request Apr 14, 2017
pex_reactor.go Outdated
try := pexR.book.PickAddress(newBias)
// NOTE always picking from the new group because old one stores already
// connected peers.
try := r.book.PickAddress(100)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is bad. The purpose of newBias is to first prioritize old (more vetted) peers when we have few connections, but to allow for new (less vetted) peers if we already have many connections. This algorithm isn't perfect, but it somewhat ensures that we prioritize connecting to more-vetted peers. Please revert.

melekes added a commit that referenced this pull request Apr 20, 2017
@melekes
Copy link
Contributor Author

melekes commented Apr 20, 2017

Rebased and reverted some commits as per Jae's comments. Done here.

This is better than waiting because while we wait, anything could happen
(crash, timeout of the code who's using addrbook, ...). If we save
immediately, we have much greater chances of success.
pex_reactor.go Outdated
for {
select {
case <-ticker.C:
r.msgCountByPeer = make(map[string]uint16)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't seem thread safe

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it have to be? peer has only 1 MConn ; MConn calls onReceive in the same thread (blocking)

@ebuchman ebuchman merged commit 1712498 into develop Apr 20, 2017
@ebuchman ebuchman deleted the pex-reactor-fixes-#9 branch April 20, 2017 21:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants