From 7b91eeb5b4af7a01d184ea5d3fb11b9976e68371 Mon Sep 17 00:00:00 2001 From: Brian Strauch Date: Sun, 16 May 2021 23:14:25 -0500 Subject: [PATCH 1/3] improve peer hints in pin.origins --- core/commands/pin/remotepin.go | 44 ++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/core/commands/pin/remotepin.go b/core/commands/pin/remotepin.go index cd5e0c4288c..3037f3f1863 100644 --- a/core/commands/pin/remotepin.go +++ b/core/commands/pin/remotepin.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "io" + "net" "sort" "strings" "text/tabwriter" @@ -24,6 +25,7 @@ import ( path "github.com/ipfs/interface-go-ipfs-core/path" "github.com/libp2p/go-libp2p-core/host" peer "github.com/libp2p/go-libp2p-core/peer" + ma "github.com/multiformats/go-multiaddr" ) var log = logging.Logger("core/commands/cmdenv") @@ -167,18 +169,36 @@ NOTE: a comma-separated notation is supported in CLI for convenience: } // Prepare Pin.origins - // Add own multiaddrs to the 'origins' array, so Pinning Service can - // use that as a hint and connect back to us (if possible) + // If CID in blockstore, add own multiaddrs to the 'origins' array + // so pinning service can use that as a hint and connect back to us. node, err := cmdenv.GetNode(env) if err != nil { return err } - if node.PeerHost != nil { + + isInBlockstore, err := node.Blockstore.Has(rp.Cid()) + if err != nil { + return err + } + + if isInBlockstore && node.PeerHost != nil { addrs, err := peer.AddrInfoToP2pAddrs(host.InfoFromHost(node.PeerHost)) if err != nil { return err } - opts = append(opts, pinclient.PinOpts.WithOrigins(addrs...)) + + cfg, err := cmdenv.GetConfig(env) + if err != nil { + return err + } + + var filteredAddrs []ma.Multiaddr + for _, addr := range addrs { + if isOriginAddr(addr, cfg.Addresses.NoAnnounce) { + filteredAddrs = append(filteredAddrs, addr) + } + } + opts = append(opts, pinclient.PinOpts.WithOrigins(filteredAddrs...)) } // Execute remote pin request @@ -240,6 +260,22 @@ NOTE: a comma-separated notation is supported in CLI for convenience: }, } +func isOriginAddr(addr ma.Multiaddr, noAnnounceAddrs []string) bool { + // IP is located at the second index: /ip4/127.0.0.1/tcp/8080 + ip := net.ParseIP(strings.Split(addr.String(), "/")[2]) + if ip.IsLoopback() { + return false + } + + for _, noAnnounceAddr := range noAnnounceAddrs { + if strings.HasPrefix(addr.String(), noAnnounceAddr) { + return false + } + } + + return true +} + var listRemotePinCmd = &cmds.Command{ Helptext: cmds.HelpText{ Tagline: "List objects pinned to remote pinning service.", From 4272dbb27e3735e3337f35dea789ef41a9d0d2d8 Mon Sep 17 00:00:00 2001 From: Brian Strauch Date: Mon, 17 May 2021 22:54:23 -0500 Subject: [PATCH 2/3] remove noannounce filtering --- core/commands/pin/remotepin.go | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/core/commands/pin/remotepin.go b/core/commands/pin/remotepin.go index 3037f3f1863..d475f43f8f1 100644 --- a/core/commands/pin/remotepin.go +++ b/core/commands/pin/remotepin.go @@ -187,14 +187,9 @@ NOTE: a comma-separated notation is supported in CLI for convenience: return err } - cfg, err := cmdenv.GetConfig(env) - if err != nil { - return err - } - var filteredAddrs []ma.Multiaddr for _, addr := range addrs { - if isOriginAddr(addr, cfg.Addresses.NoAnnounce) { + if !isLoopbackAddr(addr) { filteredAddrs = append(filteredAddrs, addr) } } @@ -260,20 +255,10 @@ NOTE: a comma-separated notation is supported in CLI for convenience: }, } -func isOriginAddr(addr ma.Multiaddr, noAnnounceAddrs []string) bool { +func isLoopbackAddr(addr ma.Multiaddr) bool { // IP is located at the second index: /ip4/127.0.0.1/tcp/8080 ip := net.ParseIP(strings.Split(addr.String(), "/")[2]) - if ip.IsLoopback() { - return false - } - - for _, noAnnounceAddr := range noAnnounceAddrs { - if strings.HasPrefix(addr.String(), noAnnounceAddr) { - return false - } - } - - return true + return ip.IsLoopback() } var listRemotePinCmd = &cmds.Command{ From 2754ffb444906db70f1325e907f4d6afda723784 Mon Sep 17 00:00:00 2001 From: Brian Strauch Date: Mon, 7 Jun 2021 12:42:50 -0500 Subject: [PATCH 3/3] remove multiaddr filtering --- core/commands/pin/remotepin.go | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/core/commands/pin/remotepin.go b/core/commands/pin/remotepin.go index d475f43f8f1..6548f29c350 100644 --- a/core/commands/pin/remotepin.go +++ b/core/commands/pin/remotepin.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "io" - "net" "sort" "strings" "text/tabwriter" @@ -25,7 +24,6 @@ import ( path "github.com/ipfs/interface-go-ipfs-core/path" "github.com/libp2p/go-libp2p-core/host" peer "github.com/libp2p/go-libp2p-core/peer" - ma "github.com/multiformats/go-multiaddr" ) var log = logging.Logger("core/commands/cmdenv") @@ -186,14 +184,7 @@ NOTE: a comma-separated notation is supported in CLI for convenience: if err != nil { return err } - - var filteredAddrs []ma.Multiaddr - for _, addr := range addrs { - if !isLoopbackAddr(addr) { - filteredAddrs = append(filteredAddrs, addr) - } - } - opts = append(opts, pinclient.PinOpts.WithOrigins(filteredAddrs...)) + opts = append(opts, pinclient.PinOpts.WithOrigins(addrs...)) } // Execute remote pin request @@ -255,12 +246,6 @@ NOTE: a comma-separated notation is supported in CLI for convenience: }, } -func isLoopbackAddr(addr ma.Multiaddr) bool { - // IP is located at the second index: /ip4/127.0.0.1/tcp/8080 - ip := net.ParseIP(strings.Split(addr.String(), "/")[2]) - return ip.IsLoopback() -} - var listRemotePinCmd = &cmds.Command{ Helptext: cmds.HelpText{ Tagline: "List objects pinned to remote pinning service.",