diff --git a/doc/provider-head-ad.md b/doc/provider-head-ad.md new file mode 100644 index 0000000..afbadab --- /dev/null +++ b/doc/provider-head-ad.md @@ -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 +``` + diff --git a/pkg/ads/flags.go b/pkg/ads/flags.go index f819bc5..298b7b2 100644 --- a/pkg/ads/flags.go +++ b/pkg/ads/flags.go @@ -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, } diff --git a/pkg/provider/provider.go b/pkg/provider/provider.go index 4760fb7..8c184c6 100644 --- a/pkg/provider/provider.go +++ b/pkg/provider/provider.go @@ -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", @@ -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.", @@ -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 } @@ -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 { @@ -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) } @@ -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