Skip to content
This repository was archived by the owner on Jun 19, 2023. It is now read-only.

Commit 713de02

Browse files
authored
Merge pull request #4803 from ipfs/feat/coreapi/swarm
coreapi: Swarm API
2 parents 47db102 + 162cac0 commit 713de02

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

coreapi.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ type CoreAPI interface {
3434
// Dht returns an implementation of Dht API
3535
Dht() DhtAPI
3636

37+
// Swarm returns an implementation of Swarm API
38+
Swarm() SwarmAPI
39+
3740
// ResolvePath resolves the path using Unixfs resolver
3841
ResolvePath(context.Context, Path) (ResolvedPath, error)
3942

key.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ type KeyAPI interface {
3333
// List lists keys stored in keystore
3434
List(ctx context.Context) ([]Key, error)
3535

36+
// Self returns the 'main' node key
37+
Self(ctx context.Context) (Key, error)
38+
3639
// Remove removes keys from keystore. Returns ipns path of the removed key
3740
Remove(ctx context.Context, name string) (Key, error)
3841
}

swarm.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package iface
2+
3+
import (
4+
"context"
5+
"errors"
6+
"time"
7+
8+
ma "gx/ipfs/QmYmsdtJ3HsodkePE3eU3TsCaP2YvPZJ4LoXnNkDE5Tpt7/go-multiaddr"
9+
"gx/ipfs/QmZNkThpqfVXs9GNbexPrfBbXSLNYeKrE7jwFM2oqHbyqN/go-libp2p-protocol"
10+
"gx/ipfs/QmbNepETomvmXfz1X5pHNFD2QuPqnqi47dTd94QJWSorQ3/go-libp2p-peer"
11+
pstore "gx/ipfs/QmfAQMFpgDU2U4BXG64qVr8HSiictfWvkSBz7Y2oDj65st/go-libp2p-peerstore"
12+
net "gx/ipfs/QmfDPh144WGBqRxZb1TGDHerbMnZATrHZggAPw7putNnBq/go-libp2p-net"
13+
)
14+
15+
var (
16+
ErrNotConnected = errors.New("not connected")
17+
ErrConnNotFound = errors.New("conn not found")
18+
)
19+
20+
// ConnectionInfo contains information about a peer
21+
type ConnectionInfo interface {
22+
// ID returns PeerID
23+
ID() peer.ID
24+
25+
// Address returns the multiaddress via which we are connected with the peer
26+
Address() ma.Multiaddr
27+
28+
// Direction returns which way the connection was established
29+
Direction() net.Direction
30+
31+
// Latency returns last known round trip time to the peer
32+
Latency() (time.Duration, error)
33+
34+
// Streams returns list of streams established with the peer
35+
Streams() ([]protocol.ID, error)
36+
}
37+
38+
// SwarmAPI specifies the interface to libp2p swarm
39+
type SwarmAPI interface {
40+
// Connect to a given peer
41+
Connect(context.Context, pstore.PeerInfo) error
42+
43+
// Disconnect from a given address
44+
Disconnect(context.Context, ma.Multiaddr) error
45+
46+
// Peers returns the list of peers we are connected to
47+
Peers(context.Context) ([]ConnectionInfo, error)
48+
49+
// KnownAddrs returns the list of all addresses this node is aware of
50+
KnownAddrs(context.Context) (map[peer.ID][]ma.Multiaddr, error)
51+
52+
// LocalAddrs returns the list of announced listening addresses
53+
LocalAddrs(context.Context) ([]ma.Multiaddr, error)
54+
55+
// ListenAddrs returns the list of all listening addresses
56+
ListenAddrs(context.Context) ([]ma.Multiaddr, error)
57+
}

0 commit comments

Comments
 (0)