Skip to content

Instantly share code, notes, and snippets.

@jbenet
Last active July 12, 2018 12:05
Show Gist options
  • Save jbenet/8e4f894021fcd23fc04086baee5889ad to your computer and use it in GitHub Desktop.
Save jbenet/8e4f894021fcd23fc04086baee5889ad to your computer and use it in GitHub Desktop.
// Discovery protocols
type libp2p.PeerDiscovery interface {
DiscoverPeers() ([]PeerInfo, error)
}
type libp2p.ContentDiscovery interface {
DiscoverContent() ([]ipld.CID, error)
}
// Routing Protocols
type libp2p.PeerRouter interface {
FindPeer(PeerID) (PeerInfo, error)
}
type libp2p.ContentRouter interface {
FindContent(ipld.CID) ([]PeerInfo, error)
}
// Go see Record Store (iprs)
func ContentRouterOnRS(RecordStore) ContentRouter { ... }
func PeerRouterOnRS(RecordStore) PeerRouter { ... }
func PeerDiscoveryOnRS(RecordStore) PeerDiscoveryOnRS { ... }
func ContentDiscoveryOnRS(RecordStore) ContentDiscoveryOnRS { ... }
// DHTs
type DHT interface {
PeerDiscovery
PeerRouter
RecordStore
}
// Pubsub
type Message interface
type PubSub interface {
PeerDiscovery
PeerRouter
RecordStore
Subscribe(Subscription) error
PublishMessage(Message) error
AcceptMessage() (Message, error)
}
// Consensus
type StateChain interface {
Record() Record
Previous() Record
All() []Record
}
type Consensus interface {
State() StateChain
Propose(Record) error
ProposeAndCommit(Record) (StateChain, error)
}
func RecordStoreOnConsensus(Consensus) RecordStore { ... }
package crypto
type Key interface {
Marshaler
}
type SigningKey interface {
Key
Sign(io.Reader) Signature
VerifySignature(Signature) (bool, error)
}
type IDKey SigningKey
type EncryptingKey interface {
Key
Encrypt(Plaintext) Ciphertext
}
type DecryptingKey interface {
Key
Decrypt(Ciphertext) Plaintext
}
type Signature interface {
Marshaler
}
type Plaintext io.Reader
type Ciphertext io.Reader
package lib
type mf.Multiaddr []byte
type mf.Multihash []byte // the hash
type ipld.CID interface { // Content ID
Encoding mf.Multcodec
Hash mf.Multihash
}
type ipld.Node interface {
Marshaler
CID() ipld.CID
}
type Marshaler interface {
Marshal() ([]byte, error)
}
package libp2p.net
type Endpoint struct {
ID PeerID
Key IDKey
Addr mf.Multiaddr
}
type Conn interface {
Local() Endpoint
Remote() Endpoint
Transport() Transport
}
type EncryptedConn Conn
type MuxConn interface {
Conn
NewStream() (Conn, error)
}
type Stream interface {
io.Reader
io.Writer
Conn() Conn
Protocol() protocol.ID
}
type Dialer interface {
Dial(raddr ma.Multiaddr) (Conn, error)
Matches(ma.Multiaddr) bool
}
type Listener interface {
Accept() (Conn, error)
Close() error
Addr() net.Addr
Multiaddr() ma.Multiaddr
}
type Transport interface {
Dialer(laddr ma.Multiaddr, opts ...DialOpt) (Dialer, error)
Listen(laddr ma.Multiaddr) (Listener, error)
Matches(ma.Multiaddr) bool
}
type Switch interface {
Interfaces() []mf.Multiaddr
Listen(ma.Multiaddr) (Listener, error)
ListenAddrs() []ma.Multiaddr
Dialer() Dialer
SetStreamHandler(StreamHandler)
SetConnHandler(ConnHandler)
}
package libp2p
type libp2p.Node interface {
ID() PeerID
Key() SigningKey
PeerStore() PeerStore
Switch() Switch
MountProtocol(Path, Protocol)
Connect(PeerID) error
ConnectInfo(*PeerInfo) error
}
package libp2p
// the hash of a public Key
type PeerID mf.Multihash
type PeerInfo struct {
ID PeerID
Addrs []mf.Multiaddr
}
type PeerStore map[PeerID]*PeerInfo
type Path string
type ProtocolID string
type Protocol interface {
ID() ProtocolID
SetNode(libp2p.Node)
}
type StreamProtocol interface {
Protocol
StreamHandler() StreamHandler
}
type PacketProtocol interface {
Protocol
PacketHandler() PacketHandler
}
type StreamHandler interface {
Handle(Stream)
}
type PacketHandler interface {
Handle(Packet)
}
package iprs
// https://github.com/libp2p/specs/blob/master/IPRS.md
type Record interface {
ipld.Node
RecordType() RecordType // comes from ipld.Type
Value() []byte
Valid() bool
OrdersAfter(Record) bool // or BetterThan or After or ...
}
type RecordType interface {
ipld.Node
Validate(Record) (bool, error)
}
type RecordKey interface {
Type() RecordType
String() string // whole thing
}
type RecordStore interface {
// Either consistent or sloppy
PutRecords(RecordKey, []Record) error
GetRecords(RecordKey) ([]Record, error)
}
type SignedRecord interface {
Record
Signature() Signature
}
type EncryptedRecord interface {
Decrypt(DecryptionKey) Record
}
// kinds of record
type ProviderRecord interface {
SignedRecord
Providing() ipld.CID
Provider() PeerID
}
type PointerRecord interface {
SignedRecord
Pointer() ipld.CID // CID of SigningKey or key itself
Value() interface{}
}
type FeedRecord or ChainRecord interface {
Record
Parents() []ipld.CID
}
@jbenet
Copy link
Author

jbenet commented Jul 12, 2018

This is far from perfect. needs much work. it's a draft

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment