Skip to content

Commit

Permalink
Flag to show only publisher addr info (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
gammazero authored Jan 24, 2024
1 parent c006200 commit 4a352f9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 16 deletions.
14 changes: 14 additions & 0 deletions doc/provider-head-ad.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## Get the Head Advertisement for Providers

The get the head advertisement for every provider:

```shell
ipni provider --all --i=https://cid.contact --publisher | xargs -I addrinfo -R 1 ipni ads get --head --ai addrinfo
```

To get the head advertisement for a single provider:

```shell
ipni provider --pid=12D3KooWC8QzjdzWynwYybjDLKa1YbPiRXUjwsibERubatgmQP51 --i=https://cid.contact --publisher | xargs ipni ads get --head --ai
```

4 changes: 2 additions & 2 deletions pkg/ads/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
var addrInfoFlag = &cli.StringFlag{
Name: "addr-info",
Usage: "Publisher's address info in form of libp2p multiaddr info.\n" +
"Example GraphSync: /ip4/1.2.3.4/tcp/1234/p2p/12D3KooWE8yt84RVwW3sFcd6WMjbUdWrZer2YtT4dmtj3dHdahSZ\n" +
"Example HTTP: /ip4/1.2.3.4/tcp/1234/http/p2p/12D3KooWE8yt84RVwW3sFcd6WMjbUdWrZer2YtT4dmtj3dHdahSZ",
"Example ipnisync: /ip4/1.2.3.4/tcp/1234/p2p/12D3KooWE8yt84RVwW3sFcd6WMjbUdWrZer2YtT4dmtj3dHdahSZ\n" +
"Example HTTP: /ip4/1.2.3.4/tcp/1234/http/p2p/12D3KooWE8yt84RVwW3sFcd6WMjbUdWrZer2YtT4dmtj3dHdahSZ",
Aliases: []string{"ai"},
Required: true,
}
Expand Down
34 changes: 20 additions & 14 deletions pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ var providerFlags = []cli.Flag{
Name: "diff-pub",
Usage: "Only show providers whose publisher ID is different from the provider ID.",
},
&cli.BoolFlag{
Name: "error",
Usage: "Only show providers that have a LastError. If --count then show count of providers with LastError.",
},
&cli.BoolFlag{
Name: "follow-dist",
Aliases: []string{"fd"},
Usage: "Continue showing distance updates for providers",
},
&cli.BoolFlag{
Name: "error",
Usage: "Only show providers that have a LastError. If --count then show count of providers with LastError.",
},
&cli.BoolFlag{
Name: "id-only",
Usage: "Only show provider's peer ID",
Expand All @@ -95,6 +95,11 @@ var providerFlags = []cli.Flag{
Usage: "Limit on number of advertisements when finding distance. 0 for unlimited.",
Value: 5000,
},
&cli.BoolFlag{
Name: "publisher",
Aliases: []string{"pub"},
Usage: "Only print publisher address info.",
},
&cli.StringFlag{
Name: "topic",
Usage: "Topic on which index advertisements are published. Only needed to get head advertisement via Graphsync with non-standard topic.",
Expand Down Expand Up @@ -190,11 +195,6 @@ func getProvider(cctx *cli.Context, pc *pcache.ProviderCache, peerID peer.ID) er
return nil
}

if cctx.Bool("id-only") {
fmt.Println(prov.AddrInfo.ID)
return nil
}

showProviderInfo(cctx, prov)
return nil
}
Expand Down Expand Up @@ -253,7 +253,6 @@ func listProviders(cctx *cli.Context, exclude map[peer.ID]struct{}) error {
}

diffPub := cctx.Bool("diff-pub")
idOnly := cctx.Bool("id-only")

for _, pinfo := range provs {
if _, ok := exclude[pinfo.AddrInfo.ID]; ok {
Expand All @@ -265,10 +264,6 @@ func listProviders(cctx *cli.Context, exclude map[peer.ID]struct{}) error {
if diffPub && pinfo.AddrInfo.ID == pinfo.Publisher.ID {
continue
}
if idOnly {
fmt.Println(pinfo.AddrInfo.ID)
continue
}
showProviderInfo(cctx, pinfo)
}

Expand Down Expand Up @@ -314,6 +309,17 @@ func followDistance(cctx *cli.Context, include, exclude map[peer.ID]struct{}, pc
}

func showProviderInfo(cctx *cli.Context, pinfo *model.ProviderInfo) {
if cctx.Bool("id-only") {
fmt.Println(pinfo.AddrInfo.ID)
return
}
if cctx.Bool("publisher") {
if pinfo.Publisher != nil && len(pinfo.Publisher.Addrs) != 0 {
fmt.Printf("%s/p2p/%s\n", pinfo.Publisher.Addrs[0], pinfo.Publisher.ID)
}
return
}

fmt.Println("Provider", pinfo.AddrInfo.ID)
fmt.Println(" Addresses:", pinfo.AddrInfo.Addrs)
var adCidStr string
Expand Down

0 comments on commit 4a352f9

Please sign in to comment.