Skip to content
This repository has been archived by the owner on Sep 6, 2022. It is now read-only.

Commit

Permalink
remove SignedRoutingStateFromHost helper
Browse files Browse the repository at this point in the history
moving this to go-libp2p
  • Loading branch information
yusefnapora committed Dec 20, 2019
1 parent 1d5e4ad commit b57c502
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 188 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ require (
github.com/minio/sha256-simd v0.1.1
github.com/mr-tron/base58 v1.1.3
github.com/multiformats/go-multiaddr v0.2.0
github.com/multiformats/go-multiaddr-net v0.1.1
github.com/multiformats/go-multihash v0.0.10
github.com/multiformats/go-varint v0.0.1
github.com/smola/gocompat v0.2.0
Expand Down
56 changes: 0 additions & 56 deletions host/helpers.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
package host

import (
"errors"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p-core/peerstore"
"github.com/libp2p/go-libp2p-core/routing"
ma "github.com/multiformats/go-multiaddr"
manet "github.com/multiformats/go-multiaddr-net"
)

// InfoFromHost returns a peer.AddrInfo struct with the Host's ID and all of its Addrs.
Expand All @@ -16,54 +11,3 @@ func InfoFromHost(h Host) *peer.AddrInfo {
Addrs: h.Addrs(),
}
}

// SignedRoutingStateFromHost returns a SignedRoutingState record containing
// the Host's listen addresses, signed with the Host's private key.
//
// By default, only publicly routable addresses will be included.
// To include loopback and LAN addresses, pass in the IncludeLocalAddrs option:
//
// state := SignedRoutingStateFromHost(h, IncludeLocalAddrs)
func SignedRoutingStateFromHost(h minimalHost, opts ...Option) (*routing.SignedRoutingState, error) {
cfg := config{}
for _, opt := range opts {
opt(&cfg)
}

privKey := h.Peerstore().PrivKey(h.ID())
if privKey == nil {
return nil, errors.New("unable to find host's private key in peerstore")
}

var addrs []ma.Multiaddr
if cfg.includeLocalAddrs {
addrs = h.Addrs()
} else {
for _, a := range h.Addrs() {
if manet.IsPublicAddr(a) {
addrs = append(addrs, a)
}
}
}

return routing.MakeSignedRoutingState(privKey, addrs)
}

// IncludeLocalAddrs can be passed into SignedRoutingStateFromHost to
// produce a routing record with LAN and loopback addresses included.
func IncludeLocalAddrs(cfg *config) {
cfg.includeLocalAddrs = true
}

// minimalHost is the subset of the Host interface that's required by
// SignedRoutingStateFromHost.
type minimalHost interface {
ID() peer.ID
Peerstore() peerstore.Peerstore
Addrs() []ma.Multiaddr
}

type Option func(cfg *config)
type config struct {
includeLocalAddrs bool
}
131 changes: 0 additions & 131 deletions host/helpers_test.go

This file was deleted.

0 comments on commit b57c502

Please sign in to comment.