Skip to content

Commit

Permalink
Merge pull request ipfs#27 from JustinDrake/cleanup
Browse files Browse the repository at this point in the history
DRY up NewDHT
  • Loading branch information
whyrusleeping authored Nov 15, 2016
2 parents 853debe + f292dce commit 3efe960
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,11 @@ 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 := makeDHT(ctx, h, dstore)

// register for network notifs.
dht.host.Network().Notify((*netNotifiee)(dht))

dht.proc = goprocessctx.WithContextAndTeardown(ctx, func() error {
// remove ourselves from network notifs.
dht.host.Network().StopNotify((*netNotifiee)(dht))
return nil
})

dht.proc.AddChild(dht.providers.Process())
dht := NewDHTClient(ctx, h, dstore)

h.SetStreamHandler(ProtocolDHT, dht.handleNewStream)
h.SetStreamHandler(ProtocolDHTOld, dht.handleNewStream)

dht.Validator["pk"] = record.PublicKeyValidator
dht.Selector["pk"] = record.PublicKeySelector


return dht
}

Expand Down

0 comments on commit 3efe960

Please sign in to comment.