Skip to content

Conversation

@tomaka
Copy link
Member

@tomaka tomaka commented Jan 3, 2018

Based over #81

Adds the swarm function, which takes an upgraded Transport and a closure. The closure is called whenever a new node or a new substream of a node connected to us, and must turn the result of the upgrade into a Future<Item = ()>.

The function returns a SwarmController and a Future. The controller can be used to control the behaviour of the swarm, and the Future must be driven to completion.

type Item = ();
type Error = IoError;

fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
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 a massively long function, is there any way to break it up in more comprehensible pieces? It's not like it's super hard to understand, it's just the same pattern over and over again, but I'd be inclined to organize it into smaller functions.

Copy link
Member Author

Choose a reason for hiding this comment

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

I went with a long function like this, because in my opinion it would be more confusing to use separate functions or macros. But I can give it a shot if you think it would be better.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, it's hard to say. You may be right, because it is a simple pattern just repeating. I don't have a strong opinion on it. Keep it if you think this is the cleanest way.

@tomaka tomaka merged commit 5f65515 into libp2p:master Jan 3, 2018
@tomaka tomaka deleted the swarm branch January 3, 2018 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants