Documentation
¶
Overview ¶
Provides subscibing and publishng to events. Event do not have a clear peer as target, but propagate through the whole netork and are accepted from everyone who is subscribed to it. The propagation happen through the already existing connections.
LocalServer ¶
Identification.go ¶
Swarm: main functions
Index ¶
- Constants
- Variables
- func AuthStateToString(state AUTH_STATE) string
- func MakeTemporaryTwoHostNetwork(path string) (*Host, *Host, error)
- func NewDAGService(owner string, session exchange.Interface, ownerstore datastore.TxnDatastore, ...) ipld.DAGService
- func RepeatableData(size int) []byte
- type AUTH_STATE
- type Adder
- type BootstrapConfig
- type DataService
- type Event
- type Host
- func (h *Host) Addresses(peer PeerID) ([]ma.Multiaddr, error)
- func (h *Host) CloseConnection(peer PeerID, force bool) error
- func (h *Host) Connect(ctx context.Context, peer PeerID, keep_open bool) error
- func (h *Host) CreateSwarm(ctx context.Context, states []State) (*Swarm, error)
- func (h *Host) CreateSwarmWithID(ctx context.Context, id SwarmID, states []State) (*Swarm, error)
- func (h *Host) FindProviders(ctx context.Context, cid utils.Cid, num int) ([]PeerID, error)
- func (h *Host) FindProvidersAsync(ctx context.Context, cid utils.Cid, num int) (chan PeerID, error)
- func (h *Host) FindSwarmMember(ctx context.Context, id SwarmID) (PeerID, error)
- func (h *Host) GetPath() string
- func (h *Host) GetSwarm(id SwarmID) (*Swarm, error)
- func (h *Host) ID() PeerID
- func (h *Host) IsConnected(peer PeerID) bool
- func (h *Host) JoinSwarm(ctx context.Context, id SwarmID, states []State, knownPeers []PeerID) (*Swarm, error)
- func (h *Host) Keys() (crypto.PrivKey, crypto.PubKey)
- func (h *Host) OwnAddresses() []ma.Multiaddr
- func (h *Host) Peers(connectedOnly bool) []PeerID
- func (h *Host) Provide(ctx context.Context, cid utils.Cid) error
- func (h *Host) Reachability() string
- func (h *Host) Routing() *kaddht.IpfsDHT
- func (h *Host) SetAdress(peer PeerID, addr ma.Multiaddr) error
- func (self *Host) SetMultipleAdress(peer PeerID, addrs []ma.Multiaddr) error
- func (h *Host) Start(shouldBootstrap bool) error
- func (h *Host) Stop(ctx context.Context) error
- func (h *Host) Swarms() []*Swarm
- type HostRPCApi
- type OwnerAwareBlockService
- func (self *OwnerAwareBlockService) AddBlock(o blocks.Block) error
- func (self *OwnerAwareBlockService) AddBlocks(bs []blocks.Block) error
- func (self *OwnerAwareBlockService) Blockstore() blockstore.Blockstore
- func (self *OwnerAwareBlockService) Close() error
- func (self *OwnerAwareBlockService) DeleteBlock(c cid.Cid) error
- func (self *OwnerAwareBlockService) Exchange() exchange.Interface
- func (self *OwnerAwareBlockService) GetBlock(ctx context.Context, c cid.Cid) (blocks.Block, error)
- func (self *OwnerAwareBlockService) GetBlocks(ctx context.Context, ks []cid.Cid) <-chan blocks.Block
- type OwnerAwareRouting
- type PeerID
- type PeerSet
- type ReplicaAPI
- type ReplicaReadAPI
- type State
- type StateEvent
- type StateObserver
- type State_Event_Type
- type Subscription
- type SubscriptionFilter
- type Swarm
- func (s *Swarm) AddPeer(ctx context.Context, pid PeerID, state AUTH_STATE) error
- func (s *Swarm) ChangePeer(ctx context.Context, peer PeerID, auth AUTH_STATE) error
- func (s *Swarm) Close(ctx context.Context)
- func (s *Swarm) GetHost() *Host
- func (self *Swarm) GetPath() string
- func (s *Swarm) GetPeers(state AUTH_STATE) []PeerID
- func (s *Swarm) HasPeer(peer PeerID) bool
- func (self *Swarm) PeerAuth(peer PeerID) AUTH_STATE
- func (s *Swarm) RemovePeer(ctx context.Context, peer PeerID) error
- type SwarmConfOp
- type SwarmConfiguration
- func (self *SwarmConfiguration) Apply(data []byte) interface{}
- func (self *SwarmConfiguration) GetPeers(state AUTH_STATE) []PeerID
- func (self *SwarmConfiguration) HasPeer(peer PeerID) bool
- func (self *SwarmConfiguration) LoadSnapshot(data []byte) error
- func (self *SwarmConfiguration) PeerAuth(peer PeerID) AUTH_STATE
- func (self *SwarmConfiguration) Snapshot() ([]byte, error)
- type SwarmID
Constants ¶
const ( AUTH_NONE = AUTH_STATE(0) AUTH_READONLY = AUTH_STATE(1) AUTH_READWRITE = AUTH_STATE(2) )
possible states
const ( STATE_EVENT_PEER_ACTIVE = replica.EVENT_PEER_ADDED STATE_EVENT_PEER_INACTIVE = replica.EVENT_PEER_REMOVED STATE_EVENT_MAJORITY_AVAILABLE = replica.EVENT_MAJORITY_AVAILABLE STATE_EVENT_MAJORITY_LOST = replica.EVENT_MAJORITY_LOST )
const Error_Arguments = "arguments_wrong" // arguments are invalid (e.g. wrong number, wrong type)
const Error_Authorisation = "authorisation_invalid" // error due to wrong authorisation
const Error_Data = "data_share_failed" // For all kind of internal proccesses
const Error_Invalid_Data = "data_invalid" // For all kind of wrong data errors
const Error_Operation_Invalid = "operation_invalid" // User operation not possible with current application state
const Error_Process = "process_failed" // For all kind of proccesses or operations
const Error_Setup = "setup_invalid" // The datastructures are not setup correctly
Variables ¶
var InvalidPeer = PeerID("")
Functions ¶
func AuthStateToString ¶
func AuthStateToString(state AUTH_STATE) string
func NewDAGService ¶
func NewDAGService(owner string, session exchange.Interface, ownerstore datastore.TxnDatastore, blockstore blockstore.Blockstore) ipld.DAGService
func RepeatableData ¶
Types ¶
type AUTH_STATE ¶
type AUTH_STATE uint
A type describing a state of authorisation
func AuthStateFromString ¶
func AuthStateFromString(state string) (AUTH_STATE, error)
type Adder ¶
Adder builds merkle trees from files and adds the to bitswap
type BootstrapConfig ¶
type BootstrapConfig struct {
// MinPeerThreshold governs whether to bootstrap more connections. If the
// node has less open connections than this number, it will open connections
// to the bootstrap nodes. From there, the routing system should be able
// to use the connections to the bootstrap nodes to connect to even more
// peers. Routing systems like the IpfsDHT do so in their own Bootstrap
// process, which issues random queries to find more peers.
MinPeerThreshold int
// Period governs the periodic interval at which the node will
// attempt to bootstrap. The bootstrap process is not very expensive, so
// this threshold can afford to be small (<=30s).
Period time.Duration
// ConnectionTimeout determines how long to wait for a bootstrap
// connection attempt before cancelling it.
ConnectionTimeout time.Duration
// BootstrapPeers is a function that returns a set of bootstrap peers
// for the bootstrap process to use. This makes it possible for clients
// to control the peers the process uses at any moment.
BootstrapPeers func() []peer.AddrInfo
// The logger used to log all bootstrap messages
Logger hclog.Logger
}
BootstrapConfig specifies parameters used in an IpfsNode's network bootstrapping process.
func GetDefaultBootstrapConfig ¶
func GetDefaultBootstrapConfig(log hclog.Logger) BootstrapConfig
type DataService ¶
type DataService interface {
Add(ctx context.Context, path string) (utils.Cid, error) //adds a file or directory
AddData(ctx context.Context, data []byte) (utils.Cid, error) //adds a Blockifyer
AddAsync(path string) (utils.Cid, error) //adds a file or directory, but returns when the local operation is done
Drop(ctx context.Context, id utils.Cid) error //removes a file or directory
Fetch(ctx context.Context, id utils.Cid) error //Fetches the given data
FetchAsync(id utils.Cid) error //Fetches the given data async
Get(ctx context.Context, id utils.Cid) (io.Reader, error) //gets the file described by the id (fetches if needed)
Write(ctx context.Context, id utils.Cid, path string) (string, error) //writes the file or directory to the given path (fetches if needed)
ReadChannel(ctx context.Context, id utils.Cid) (chan []byte, error) //reads the data in individual binary blocks (does not work for directory)
HasLocal(id utils.Cid) bool //checks if the given id is available locally
Close()
}
the data service interface!
func NewDataService ¶
func NewDataService(host *Host) (DataService, error)
type Host ¶
type Host struct {
//serivces the host provides
Rpc *hostRpcService
Data DataService
Event *hostEventService
// contains filtered or unexported fields
}
func MakeTemporaryTestingHost ¶
for external modules that need a host for tessting
func NewHost ¶
func NewHost(router *connection.Router, logger hclog.Logger) *Host
Host creates p2p host which manages all peer connections
func (*Host) CloseConnection ¶
Closes the connection to given peer. If force is true, it will be closed. Otherwise it stays open and the host is free to close it later in case of too many open connections
func (*Host) Connect ¶
Tries to connect to given peer. If keep_open is true the connection stays always open, otherwise it could be closed later in case too many connections are open
func (*Host) CreateSwarm ¶
func (*Host) CreateSwarmWithID ¶
func (*Host) FindProviders ¶
find peers that provide the given cid. The returned slice can have less than num entries, depending on the find results
func (*Host) FindProvidersAsync ¶
find peers that provide the given cid
func (*Host) FindSwarmMember ¶
Finds a peer active in current swarm
func (*Host) IsConnected ¶
func (*Host) OwnAddresses ¶
func (*Host) Reachability ¶
func (*Host) SetMultipleAdress ¶
type HostRPCApi ¶
type HostRPCApi struct {
// contains filtered or unexported fields
}
RPC Api of the host
type OwnerAwareBlockService ¶
type OwnerAwareBlockService struct {
// contains filtered or unexported fields
}
implementation of the IPFS Blockservice interface. reason to have our own is to allow ownership of blocks for our swarm implementation it works together with OwnerAwareRouting
func NewOwnerAwareBlockService ¶
func NewOwnerAwareBlockService(owner string, ds datastore.TxnDatastore, bs blockstore.Blockstore, service exchange.Interface) *OwnerAwareBlockService
creates a blockservice with a datastore for ownership data and a blockstore for storing the block data. Note: Could be the same datastore for both
func (*OwnerAwareBlockService) AddBlock ¶
func (self *OwnerAwareBlockService) AddBlock(o blocks.Block) error
AddBlock puts a given block to the underlying datastore
func (*OwnerAwareBlockService) AddBlocks ¶
func (self *OwnerAwareBlockService) AddBlocks(bs []blocks.Block) error
AddBlocks adds a slice of blocks at the same time using batching capabilities of the underlying datastore whenever possible.
func (*OwnerAwareBlockService) Blockstore ¶
func (self *OwnerAwareBlockService) Blockstore() blockstore.Blockstore
Blockstore returns a reference to the underlying blockstore
func (*OwnerAwareBlockService) Close ¶
func (self *OwnerAwareBlockService) Close() error
func (*OwnerAwareBlockService) DeleteBlock ¶
func (self *OwnerAwareBlockService) DeleteBlock(c cid.Cid) error
DeleteBlock deletes the given block from the blockservice.
func (*OwnerAwareBlockService) Exchange ¶
func (self *OwnerAwareBlockService) Exchange() exchange.Interface
Exchange returns a reference to the underlying exchange (usually bitswap)
func (*OwnerAwareBlockService) GetBlocks ¶
func (self *OwnerAwareBlockService) GetBlocks(ctx context.Context, ks []cid.Cid) <-chan blocks.Block
GetBlocks does a batch request for the given cids, returning blocks as they are found, in no particular order.
It may not be able to find all requested blocks (or the context may be canceled). In that case, it will close the channel early. It is up to the consumer to detect this situation and keep track which blocks it has received and which it hasn't.
type OwnerAwareRouting ¶
type OwnerAwareRouting struct {
// contains filtered or unexported fields
}
the routing type used by bitswap network
func NewOwnerAwareRouting ¶
func NewOwnerAwareRouting(host *Host, ownerStore datastore.Datastore) (OwnerAwareRouting, error)
func (OwnerAwareRouting) FindProvidersAsync ¶
func (self OwnerAwareRouting) FindProvidersAsync(ctx context.Context, id cid.Cid, num int) <-chan peerstore.PeerInfo
Search for peers who are able to provide a given key
type PeerSet ¶
type PeerSet struct {
// contains filtered or unexported fields
}
A concurency safe store for peers
func NewPeerSet ¶
func NewPeerSet() *PeerSet
type ReplicaAPI ¶
type ReplicaAPI struct {
// contains filtered or unexported fields
}
func (*ReplicaAPI) AddCommand ¶
type ReplicaReadAPI ¶
type ReplicaReadAPI struct {
// contains filtered or unexported fields
}
Api callable by Read Only auth
func (*ReplicaReadAPI) Join ¶
func (self *ReplicaReadAPI) Join(ctx context.Context, peer PeerID, ret *AUTH_STATE) error
join is ReadAPI as also read only peers need to call it for themself. If joining is allowed will be checked in this function
type State ¶
func SwarmStates ¶
little helper to add swarms to the states
type StateEvent ¶
type StateObserver ¶
type State_Event_Type ¶
type State_Event_Type = replica.Event_Type
type Subscription ¶
type Subscription struct {
// contains filtered or unexported fields
}
a small wrapper for subscription type supports custom message type
func (Subscription) Cancel ¶
func (self Subscription) Cancel()
Cancels the subscription. Next will return with an error and no more events will be catched
func (Subscription) Next ¶
func (self Subscription) Next(ctx context.Context) (*Event, error)
blocks till a event arrives, the context is canceled or the subscription itself is canceld
func (Subscription) Topic ¶
func (self Subscription) Topic() string
type SubscriptionFilter ¶
type SubscriptionFilter struct {
// contains filtered or unexported fields
}
Filters subscriptions based on P2P authorisation
func (SubscriptionFilter) CanSubscribe ¶
func (self SubscriptionFilter) CanSubscribe(topic string) bool
CanSubscribe returns true if the topic is of interest and we can subscribe to it
func (SubscriptionFilter) FilterIncomingSubscriptions ¶
func (self SubscriptionFilter) FilterIncomingSubscriptions(sender peer.ID, subopts []*pb.RPC_SubOpts) ([]*pb.RPC_SubOpts, error)
we filter every subscription that is not authorized
type Swarm ¶
type Swarm struct {
//provided services
Event *swarmEventService
Rpc *swarmRpcService
Data DataService
State *sharedStateService
ID SwarmID
// contains filtered or unexported fields
}
Type that represents a collection if peers which are connected together and form a swarm. It allows to share data between all peers, as well as have common events and provide rpc calls.
A swarm does always allow reading for its pears! It is not possible to make it secure, don't use it if the shared information is not public. Even if a peer is not added it is easily possible to catch the information for attacking nodes.
It does allow for a certain Authorisation sheme: ReadOnly or ReadWrite. It has the folloing impact on the swarm services:
- RPC: -- ReadOnly Peer can be adressed for all RPC calls it offers (may fail dependend on its on AUTH info) -- ReadOnly Peer is allowed to call all registered ReadOnly RPCs of this swarm -- ReadOnly Peer is not allowed to call all registered ReadWrtie RPCs of this swarm. Those calls will fail. -- ReadWrite Peer is additionaly allowed to call ReadWrite RPC's of this swarm
- Event: -- ReadOnly Peer will receive all events send from this swarm (may fail dependend on its on AUTH info) -- ReadOnly Peer can publish ReadOnly events to this swarm -- ReadOnly Peer can not publish ReadWrite event to this swarm -- ReadWrite Peer can additionally publish ReadWrite events to this swarm
- Data: -- ReadOnly Peer will receive all shared file information and the files itself -- ReadOnly Peer will not be able to add new files to the swarm -- ReadWrite Peer will be able to add new files to the swarm
func (*Swarm) ChangePeer ¶
func (*Swarm) GetPeers ¶
func (s *Swarm) GetPeers(state AUTH_STATE) []PeerID
returns all peers with the given or higher auth state. E.g. AUTH_READONLY returns all peers with read only as well as read write auth If you want all peers use AUTH_NONE
func (*Swarm) PeerAuth ¶
func (self *Swarm) PeerAuth(peer PeerID) AUTH_STATE
type SwarmConfOp ¶
type SwarmConfOp struct {
Remove bool
Peer PeerID
Auth AUTH_STATE
}
func (SwarmConfOp) ToBytes ¶
func (self SwarmConfOp) ToBytes() []byte
type SwarmConfiguration ¶
type SwarmConfiguration struct {
Peer map[PeerID]AUTH_STATE
// contains filtered or unexported fields
}
this is a replica state
func (*SwarmConfiguration) Apply ¶
func (self *SwarmConfiguration) Apply(data []byte) interface{}
state interface
func (*SwarmConfiguration) GetPeers ¶
func (self *SwarmConfiguration) GetPeers(state AUTH_STATE) []PeerID
func (*SwarmConfiguration) HasPeer ¶
func (self *SwarmConfiguration) HasPeer(peer PeerID) bool
func (*SwarmConfiguration) LoadSnapshot ¶
func (self *SwarmConfiguration) LoadSnapshot(data []byte) error
state interface
func (*SwarmConfiguration) PeerAuth ¶
func (self *SwarmConfiguration) PeerAuth(peer PeerID) AUTH_STATE
func (*SwarmConfiguration) Snapshot ¶
func (self *SwarmConfiguration) Snapshot() ([]byte, error)
state interface