This repository has been archived by the owner on Sep 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* flatten out slim packages in routing. * simplify naming in discovery. * break up big monolithic files into constituents (network, pnet). * renames for consistency.
- Loading branch information
Showing
24 changed files
with
238 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package discovery | ||
|
||
import "time" | ||
|
||
// DiscoveryOpt is a single discovery option. | ||
type Option func(opts *Options) error | ||
|
||
// DiscoveryOpts is a set of discovery options. | ||
type Options struct { | ||
Ttl time.Duration | ||
Limit int | ||
|
||
// Other (implementation-specific) options | ||
Other map[interface{}]interface{} | ||
} | ||
|
||
// Apply applies the given options to this DiscoveryOpts | ||
func (opts *Options) Apply(options ...Option) error { | ||
for _, o := range options { | ||
if err := o(opts); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// TTL is an option that provides a hint for the duration of an advertisement | ||
func TTL(ttl time.Duration) Option { | ||
return func(opts *Options) error { | ||
opts.Ttl = ttl | ||
return nil | ||
} | ||
} | ||
|
||
// Limit is an option that provides an upper bound on the peer count for discovery | ||
func Limit(limit int) Option { | ||
return func(opts *Options) error { | ||
opts.Limit = limit | ||
return nil | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package network | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/libp2p/go-libp2p-core/peer" | ||
ic "github.com/libp2p/go-libp2p-crypto" | ||
|
||
ma "github.com/multiformats/go-multiaddr" | ||
) | ||
|
||
// Conn is a connection to a remote peer. It multiplexes streams. | ||
// Usually there is no need to use a Conn directly, but it may | ||
// be useful to get information about the peer on the other side: | ||
// stream.Conn().RemotePeer() | ||
type Conn interface { | ||
io.Closer | ||
|
||
ConnSecurity | ||
ConnMultiaddrs | ||
|
||
// NewStream constructs a new Stream over this conn. | ||
NewStream() (Stream, error) | ||
|
||
// GetStreams returns all open streams over this conn. | ||
GetStreams() []Stream | ||
|
||
// Stat stores metadata pertaining to this conn. | ||
Stat() Stat | ||
} | ||
|
||
// ConnSecurity is the interface that one can mix into a connection interface to | ||
// give it the security methods. | ||
type ConnSecurity interface { | ||
// LocalPeer returns our peer ID | ||
LocalPeer() peer.ID | ||
|
||
// LocalPrivateKey returns our private key | ||
LocalPrivateKey() ic.PrivKey | ||
|
||
// RemotePeer returns the peer ID of the remote peer. | ||
RemotePeer() peer.ID | ||
|
||
// RemotePublicKey returns the public key of the remote peer. | ||
RemotePublicKey() ic.PubKey | ||
} | ||
|
||
// ConnMultiaddrs is an interface mixin for connection types that provide multiaddr | ||
// addresses for the endpoints. | ||
type ConnMultiaddrs interface { | ||
// LocalMultiaddr returns the local Multiaddr associated | ||
// with this connection | ||
LocalMultiaddr() ma.Multiaddr | ||
|
||
// RemoteMultiaddr returns the remote Multiaddr associated | ||
// with this connection | ||
RemoteMultiaddr() ma.Multiaddr | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package network | ||
|
||
import "errors" | ||
|
||
// There are no addresses associated with a peer when they were needed. | ||
var ErrNoRemoteAddrs = errors.New("no remote addresses") | ||
|
||
// ErrNoConn is returned when attempting to open a stream to a peer with the NoDial | ||
// option and no usable connection is available. | ||
var ErrNoConn = errors.New("no usable connection to peer") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.