mirror of
https://github.com/libp2p/go-libp2p-core.git
synced 2025-04-28 17:10:14 +08:00
rename peer.Info to peer.AddrInfo.
This commit is contained in:
parent
3a54eb68d1
commit
c30d4b4050
6
alias.go
6
alias.go
@ -1,4 +1,4 @@
|
||||
// Package core provides aliases for foundational, central go-libp2p primitives for convenient access.
|
||||
// Package core provides convenient access to foundational, central go-libp2p primitives via type aliases.
|
||||
package core
|
||||
|
||||
import (
|
||||
@ -26,10 +26,10 @@ type PeerID = peer.ID
|
||||
// Refer to the docs on that type for more info.
|
||||
type ProtocolID = protocol.ID
|
||||
|
||||
// PeerInfo aliases peer.Info.
|
||||
// PeerAddrInfo aliases peer.AddrInfo.
|
||||
//
|
||||
// Refer to the docs on that type for more info.
|
||||
type PeerInfo = peer.Info
|
||||
type PeerAddrInfo = peer.AddrInfo
|
||||
|
||||
// CONSTRUCTIONS.
|
||||
|
||||
|
@ -16,7 +16,7 @@ type Advertiser interface {
|
||||
// Discoverer is an interface for peer discovery
|
||||
type Discoverer interface {
|
||||
// FindPeers discovers peers providing a service
|
||||
FindPeers(ctx context.Context, ns string, opts ...Option) (<-chan peer.Info, error)
|
||||
FindPeers(ctx context.Context, ns string, opts ...Option) (<-chan peer.AddrInfo, error)
|
||||
}
|
||||
|
||||
// Discovery is an interface that combines service advertisement and peer discovery
|
||||
|
@ -2,9 +2,9 @@ package host
|
||||
|
||||
import "github.com/libp2p/go-libp2p-core/peer"
|
||||
|
||||
// InfoFromHost returns a peer.Info struct with the Host's ID and all of its Addrs.
|
||||
func InfoFromHost(h Host) *peer.Info {
|
||||
return &peer.Info{
|
||||
// InfoFromHost returns a peer.AddrInfo struct with the Host's ID and all of its Addrs.
|
||||
func InfoFromHost(h Host) *peer.AddrInfo {
|
||||
return &peer.AddrInfo{
|
||||
ID: h.ID(),
|
||||
Addrs: h.Addrs(),
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ type Host interface {
|
||||
// peerstore. If there is not an active connection, Connect will issue a
|
||||
// h.Network.Dial, and block until a connection is open, or an error is
|
||||
// returned. // TODO: Relay + NAT.
|
||||
Connect(ctx context.Context, pi peer.Info) error
|
||||
Connect(ctx context.Context, pi peer.AddrInfo) error
|
||||
|
||||
// SetStreamHandler sets the protocol handler on the Host's Mux.
|
||||
// This is equivalent to:
|
||||
|
@ -7,22 +7,22 @@ import (
|
||||
ma "github.com/multiformats/go-multiaddr"
|
||||
)
|
||||
|
||||
// PeerInfo is a small struct used to pass around a peer with
|
||||
// AddrInfo is a small struct used to pass around a peer with
|
||||
// a set of addresses (and later, keys?).
|
||||
type Info struct {
|
||||
type AddrInfo struct {
|
||||
ID ID
|
||||
Addrs []ma.Multiaddr
|
||||
}
|
||||
|
||||
var _ fmt.Stringer = Info{}
|
||||
var _ fmt.Stringer = AddrInfo{}
|
||||
|
||||
func (pi Info) String() string {
|
||||
func (pi AddrInfo) String() string {
|
||||
return fmt.Sprintf("{%v: %v}", pi.ID, pi.Addrs)
|
||||
}
|
||||
|
||||
var ErrInvalidAddr = fmt.Errorf("invalid p2p multiaddr")
|
||||
|
||||
func InfoFromP2pAddr(m ma.Multiaddr) (*Info, error) {
|
||||
func AddrInfoFromP2pAddr(m ma.Multiaddr) (*AddrInfo, error) {
|
||||
if m == nil {
|
||||
return nil, ErrInvalidAddr
|
||||
}
|
||||
@ -53,13 +53,13 @@ func InfoFromP2pAddr(m ma.Multiaddr) (*Info, error) {
|
||||
addrs = append(addrs, ma.Join(parts[:len(parts)-1]...))
|
||||
}
|
||||
|
||||
return &Info{
|
||||
return &AddrInfo{
|
||||
ID: id,
|
||||
Addrs: addrs,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func InfoToP2pAddrs(pi *Info) ([]ma.Multiaddr, error) {
|
||||
func AddrInfoToP2pAddrs(pi *AddrInfo) ([]ma.Multiaddr, error) {
|
||||
var addrs []ma.Multiaddr
|
||||
tpl := "/" + ma.ProtocolWithCode(ma.P_P2P).Name + "/"
|
||||
for _, addr := range pi.Addrs {
|
||||
@ -72,7 +72,7 @@ func InfoToP2pAddrs(pi *Info) ([]ma.Multiaddr, error) {
|
||||
return addrs, nil
|
||||
}
|
||||
|
||||
func (pi *Info) Loggable() map[string]interface{} {
|
||||
func (pi *AddrInfo) Loggable() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"peerID": pi.ID.Pretty(),
|
||||
"addrs": pi.Addrs,
|
@ -6,7 +6,7 @@ import (
|
||||
ma "github.com/multiformats/go-multiaddr"
|
||||
)
|
||||
|
||||
func (pi Info) MarshalJSON() ([]byte, error) {
|
||||
func (pi AddrInfo) MarshalJSON() ([]byte, error) {
|
||||
out := make(map[string]interface{})
|
||||
out["ID"] = pi.ID.Pretty()
|
||||
var addrs []string
|
||||
@ -17,7 +17,7 @@ func (pi Info) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(out)
|
||||
}
|
||||
|
||||
func (pi *Info) UnmarshalJSON(b []byte) error {
|
||||
func (pi *AddrInfo) UnmarshalJSON(b []byte) error {
|
||||
var data map[string]interface{}
|
||||
err := json.Unmarshal(b, &data)
|
||||
if err != nil {
|
@ -62,7 +62,7 @@ type Peerstore interface {
|
||||
// PeerInfo returns a peer.PeerInfo struct for given peer.ID.
|
||||
// This is a small slice of the information Peerstore has on
|
||||
// that peer, useful to other services.
|
||||
PeerInfo(peer.ID) peer.Info
|
||||
PeerInfo(peer.ID) peer.AddrInfo
|
||||
|
||||
GetProtocols(peer.ID) ([]string, error)
|
||||
AddProtocols(peer.ID, ...string) error
|
||||
|
@ -26,7 +26,7 @@ const (
|
||||
type QueryEvent struct {
|
||||
ID peer.ID
|
||||
Type QueryEventType
|
||||
Responses []*peer.Info
|
||||
Responses []*peer.AddrInfo
|
||||
Extra string
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ func (qe *QueryEvent) UnmarshalJSON(b []byte) error {
|
||||
temp := struct {
|
||||
ID string
|
||||
Type int
|
||||
Responses []*peer.Info
|
||||
Responses []*peer.AddrInfo
|
||||
Extra string
|
||||
}{}
|
||||
err := json.Unmarshal(b, &temp)
|
||||
|
@ -27,7 +27,7 @@ type ContentRouting interface {
|
||||
Provide(context.Context, cid.Cid, bool) error
|
||||
|
||||
// Search for peers who are able to provide a given key
|
||||
FindProvidersAsync(context.Context, cid.Cid, int) <-chan peer.Info
|
||||
FindProvidersAsync(context.Context, cid.Cid, int) <-chan peer.AddrInfo
|
||||
}
|
||||
|
||||
// PeerRouting is a way to find information about certain peers.
|
||||
@ -35,9 +35,9 @@ type ContentRouting interface {
|
||||
// or even a DHT.
|
||||
type PeerRouting interface {
|
||||
// Find specific Peer
|
||||
// FindPeer searches for a peer with given ID, returns a peer.Info
|
||||
// FindPeer searches for a peer with given ID, returns a peer.AddrInfo
|
||||
// with relevant addresses.
|
||||
FindPeer(context.Context, peer.ID) (peer.Info, error)
|
||||
FindPeer(context.Context, peer.ID) (peer.AddrInfo, error)
|
||||
}
|
||||
|
||||
// ValueStore is a basic Put/Get interface.
|
||||
|
Loading…
Reference in New Issue
Block a user