Skip to content

Commit

Permalink
fix(driver): Fix providing id
Browse files Browse the repository at this point in the history
  • Loading branch information
gfanton committed Nov 14, 2018
1 parent bf5719e commit 66ac717
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
12 changes: 9 additions & 3 deletions core/network/p2p/discovery.go
Expand Up @@ -24,6 +24,10 @@ func DiscoveryNotify(d *Driver) discovery.Notifee {
return (*driverDiscoveryNotify)(d)
}

func Notify(d *Driver) inet.Notifiee {
return (*driverDiscoveryNotify)(d)
}

// Driver Notify
func (ddn *driverDiscoveryNotify) HandlePeerFound(pi pstore.PeerInfo) {
if err := ddn.host.Connect(context.Background(), pi); err != nil {
Expand All @@ -41,20 +45,22 @@ func (ddn *driverDiscoveryNotify) ClosedStream(net inet.Network, s inet.Stream)

func (ddn *driverDiscoveryNotify) Connected(s inet.Network, c inet.Conn) {
go func(id peer.ID) {
ddn.muSubs.Lock()
if len(ddn.subsStack) > 0 {
var newSubsStack []cid.Cid
for _, c := range ddn.subsStack {
if err := ddn.dht.Provide(context.Background(), c, true); err != nil {
// stack peer if no peer found
logger().Warn("Provide err", zap.Error(err))
logger().Warn("discover: provide err:", zap.Error(err))
newSubsStack = append(newSubsStack, c)
} else {
logger().Debug("discover: announcing", zap.String("id", c.String()))
}
}

ddn.muSubs.Lock()
ddn.subsStack = newSubsStack
ddn.muSubs.Unlock()
}
ddn.muSubs.Unlock()
}(c.RemotePeer())
}

Expand Down
7 changes: 4 additions & 3 deletions core/network/p2p/driver.go
Expand Up @@ -133,6 +133,8 @@ func newDriver(ctx context.Context, cfg driverConfig) (*Driver, error) {
}
}

host.Network().Notify(Notify(driver))

if len(cfg.bootstrap) > 0 {
if err := driver.Bootstrap(ctx, cfg.bootstrapSync, cfg.bootstrap...); err != nil {
return nil, err
Expand Down Expand Up @@ -433,13 +435,12 @@ func (d *Driver) Join(ctx context.Context, id string) error {
}

if err := d.dht.Provide(ctx, c, true); err != nil {
// stack peer if no peer found
d.stackSub(c)
logger().Warn("provide err", zap.Error(err))
} else {
logger().Debug("discover: announcing", zap.String("id", id))
}

logger().Debug("announcing", zap.String("id", id))

// Announce that you are subscribed to this conversation, but don't
// broadcast it! in this way, if you die, your announcement will die with you!
return nil
Expand Down

0 comments on commit 66ac717

Please sign in to comment.