Skip to content

Commit

Permalink
Added ipni to go-mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan6sha committed Nov 22, 2023
1 parent fdfac45 commit e2a9793
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
30 changes: 18 additions & 12 deletions exchange/fx_exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ func NewFxExchange(h host.Host, ls ipld.LinkSystem, o ...Option) (*FxExchange, e
return nil, err
}
}
if !e.ipniPublishDisabled {
e.pub, err = newIpniPublisher(h, opts)
if err != nil {
return nil, err
}
//if !e.ipniPublishDisabled {
e.pub, err = newIpniPublisher(h, opts)
if err != nil {
return nil, err
}
//}
return e, nil
}

Expand All @@ -120,14 +120,20 @@ func (e *FxExchange) GetAuthorizedPeers(ctx context.Context) ([]peer.ID, error)
return peerList, nil
}

func (e *FxExchange) IpniNotifyLink(link ipld.Link) {
log.Debugw("Notifying link to IPNI publisher...", "link", link)
e.pub.notifyReceivedLink(link)
log.Debugw("Successfully notified link to IPNI publisher", "link", link)
}

func (e *FxExchange) Start(ctx context.Context) error {
gsn := gsnet.NewFromLibp2pHost(e.h)
e.gx = gs.New(ctx, gsn, e.ls)

if err := e.pub.Start(ctx); err != nil {
return err
}
if !e.ipniPublishDisabled {
if err := e.pub.Start(ctx); err != nil {
return err
}
e.gx.RegisterIncomingBlockHook(func(p peer.ID, responseData graphsync.ResponseData, blockData graphsync.BlockData, hookActions graphsync.IncomingBlockHookActions) {
go func(link ipld.Link) {
log.Debugw("Notifying link to IPNI publisher...", "link", link)
Expand Down Expand Up @@ -374,11 +380,11 @@ func (e *FxExchange) authorized(pid peer.ID, action string) bool {
}

func (e *FxExchange) Shutdown(ctx context.Context) error {
if !e.ipniPublishDisabled {
if err := e.pub.shutdown(); err != nil {
log.Warnw("Failed to shutdown IPNI publisher gracefully", "err", err)
}
//if !e.ipniPublishDisabled {
if err := e.pub.shutdown(); err != nil {
log.Warnw("Failed to shutdown IPNI publisher gracefully", "err", err)
}
//}
e.c.CloseIdleConnections()
return e.s.Shutdown(ctx)
}
1 change: 1 addition & 0 deletions exchange/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ type Exchange interface {
Pull(context.Context, peer.ID, ipld.Link) error
SetAuth(context.Context, peer.ID, peer.ID, bool) error
Shutdown(context.Context) error
IpniNotifyLink(link ipld.Link)
}
4 changes: 4 additions & 0 deletions exchange/noop_exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ func (n NoopExchange) Shutdown(context.Context) error {
log.Debug("Shut down noop exchange.")
return nil
}

func (n NoopExchange) IpniNotifyLink(l ipld.Link) {
log.Debugw("IpniNotifyLink noop exchange.", "link", l)
}
1 change: 1 addition & 0 deletions mobile/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ func (c *Client) Put(value []byte, codec int64) ([]byte, error) {
return nil, err
}
c.markAsRecentCid(ctx, link.(cidlink.Link))
c.ex.IpniNotifyLink(link.(cidlink.Link))
return link.(cidlink.Link).Cid.Bytes(), nil
}

Expand Down

0 comments on commit e2a9793

Please sign in to comment.