Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update for the routing refactor #148

Merged
merged 4 commits into from
Jun 2, 2018
Merged

update for the routing refactor #148

merged 4 commits into from
Jun 2, 2018

Conversation

Stebalien
Copy link
Member

@Stebalien Stebalien commented May 9, 2018

GetValues was very DHT specific so the routing interface has been updated to remove that function. Instead, it has introduced general-purpose options.

This is a "minimal" alternative to #141 to avoid bundling too many changes together.

Depends on:

dht.go Outdated
@@ -67,8 +66,8 @@ type IpfsDHT struct {
}

// NewDHT creates a new DHT object with the given peer as the 'local' host
func NewDHT(ctx context.Context, h host.Host, dstore ds.Batching) *IpfsDHT {
dht := NewDHTClient(ctx, h, dstore)
func NewDHT(ctx context.Context, h host.Host, dstore ds.Batching, validator record.Validator) *IpfsDHT {
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure I like having a required record validator argument; it will also flat out break existing code.
Can we make this optional with a variadic?

Copy link
Contributor

Choose a reason for hiding this comment

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

The default should be what the old default functionality was, public key validation so that it's backwards compatible.

Copy link
Contributor

Choose a reason for hiding this comment

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

also, ergonomics.

Copy link
Member Author

@Stebalien Stebalien May 9, 2018

Choose a reason for hiding this comment

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

Yeah, good point. I was in a "get shit working at all costs" mood when I made this change.

What about just going back to exposing a Validator public field. That's closer to what we currently do (although racy if the host is up and accepting streams). The nice alternative is an options system (more code but probably better in the long run).

Copy link
Contributor

Choose a reason for hiding this comment

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

let's make it nice, there is no rush.

dht.go Outdated
@@ -77,7 +76,7 @@ func NewDHT(ctx context.Context, h host.Host, dstore ds.Batching) *IpfsDHT {
}

// NewDHTClient creates a new DHT object with the given peer as the 'local' host
func NewDHTClient(ctx context.Context, h host.Host, dstore ds.Batching) *IpfsDHT {
func NewDHTClient(ctx context.Context, h host.Host, dstore ds.Batching, validator record.Validator) *IpfsDHT {
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto.

@Stebalien
Copy link
Member Author

@vyzo I've added a new DHT constructor that takes options. This also unifies the DHT and DHTClient constructors and configures a default datastore (allows users to start using libp2p without understanding datastores).

@Stebalien Stebalien requested a review from vyzo May 15, 2018 18:06
Copy link
Contributor

@vyzo vyzo left a comment

Choose a reason for hiding this comment

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

new constructor looks good.

dht.go Outdated
@@ -65,19 +66,13 @@ type IpfsDHT struct {
plk sync.Mutex
}

// NewDHT creates a new DHT object with the given peer as the 'local' host
func NewDHT(ctx context.Context, h host.Host, dstore ds.Batching, validator record.Validator) *IpfsDHT {
Copy link
Contributor

Choose a reason for hiding this comment

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

keep those around for backwards compatibility. it is not acceptable to have to change existing working code.

Copy link
Contributor

Choose a reason for hiding this comment

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

i mean the original constructor that takes a context, host, and datastore.

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 did. I'm just reverting my change to them here. There are now three constructors:

  • NewDHT (old)
  • NewDHTClient (old)
  • New (new)

dht.go Outdated
}

// NewDHTClient creates a new DHT object with the given peer as the 'local' host
func NewDHTClient(ctx context.Context, h host.Host, dstore ds.Batching, validator record.Validator) *IpfsDHT {
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

GetValues was very DHT specific so the routing interface has been updated to
remove that function. Instead, it has introduced general-purpose options.

This is a minimal alternative to #141 to avoid bundling too many changes
together.
Note: this does mean that the DHT won't work with peer keys by default and that
the constructor signature changes. Given all the changes that'll come with the
libp2p refactor, I don't feel too bad about this.
Instead of changing the existing constructors, add a new DHT constructor that
takes options (and add DHT options).
@Stebalien Stebalien merged commit 654c41b into master Jun 2, 2018
@ghost ghost removed the status/in-progress In progress label Jun 2, 2018
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