Documentation
¶
Overview ¶
Package datahop is a mobile client for running a minimalistic datahop ipfslite node.
A datahop ipfslite node uses a persistent repo and a config file same as go-ipfs to have necessary config options cashed. It uses a global "datahop" object to run and maintain the ipfslite node.
As this package is built keeping the mobile platform in mind (using gomobile), all of the functions deals with string or byte array to support gomobile datatype.
To create the global "datahop" object and a persistent repository the client has to call "Init". It takes the location to create the repository and an "ConnectionManager".
type ConnManager struct{}
func (m ConnManager) PeerConnected(s string) {
// do something
}
func (m ConnManager) PeerDisconnected(s string) {
// do something
}
...
cm := ConnManager{}
err := Init(root, cm)
if err != nil {
panic(err)
}
Start the datahop ipfslite node by calling "Start"
err := Start()
if err != nil {
panic(err)
}
To check if the ipfslite node is running or not
isOnline := IsNodeOnline()
if isOnline {
// node is online
}
To check how much storage the ipfslite node has taken up
storageAllocated, err := DiskUsage()
if err != nil {
panic(err)
}
All the ipfslite node id related information can be obtained by the following functions. See the corresponding function definitions for more information
id := ID() ... addresses := Addrs() ... addresses := InterfaceAddrs() ... addresses := PeerInfo()
"PeerInfo" returns a string of the peer.AddrInfo []byte of the node. we can actually pass this around to connect with other nodes
peerInfo := PeerInfo()
...
// On some other node
err := ConnectWithPeerInfo(peerInfo)
if err != nil {
panic(err)
}
Clients can connect with each other using peer address aswell
err := ConnectWithAddress(otherPeerAddress)
if err != nil {
panic(err)
}
To see all the connected peers
connectedPeers := Peers()
To stop the ipfslite node
Stop()
To close the global "datahop"
Close()
To check "package" version
version := Version()
Index ¶
- Constants
- Variables
- func Add(tag string, content []byte) error
- func Addrs() ([]byte, error)
- func Bootstrap(peerInfoByteString string) error
- func Close()
- func ConnectWithAddress(address string) error
- func ConnectWithPeerInfo(peerInfoByteString string) error
- func DiskUsage() (int64, error)
- func Get(tag string) ([]byte, error)
- func GetTags() ([]byte, error)
- func ID() string
- func Init(root string, connManager ConnectionManager, discDriver DiscoveryDriver, ...) error
- func InterfaceAddrs() ([]byte, error)
- func IsNodeOnline() bool
- func PeerInfo() string
- func Peers() ([]byte, error)
- func Start(shouldBootstrap bool) error
- func StartDiscovery() error
- func State() ([]byte, error)
- func Stop()
- func StopDiscovery() error
- func UpdateTopicStatus(topic string, value []byte)
- func Version() string
- type AdvertisementNotifier
- type AdvertisingDriver
- type ConnectionManager
- type DiscoveryDriver
- type DiscoveryNotifier
- type Notifee
- type Notifier
- func (n *Notifier) ClosedStream(network.Network, network.Stream)
- func (n *Notifier) Connected(net network.Network, c network.Conn)
- func (n *Notifier) Disconnected(net network.Network, c network.Conn)
- func (n *Notifier) Listen(network.Network, ma.Multiaddr)
- func (n *Notifier) ListenClose(network.Network, ma.Multiaddr)
- func (n *Notifier) OpenedStream(net network.Network, s network.Stream)
- type Service
- type WifiConnection
- type WifiConnectionNotifier
- type WifiHotspot
- type WifiHotspotNotifier
Constants ¶
const ( NoPeersConnected = "No Peers connected" CRDTStatus = "datahop-crdt-status" )
const ServiceTag = "_datahop-discovery._ble"
Variables ¶
var ( ErrNoPeersConnected = errors.New("no Peers connected") ErrNoPeerAddress = errors.New("could not get peer address") )
Functions ¶
func ConnectWithAddress ¶
ConnectWithAddress Connects to a given peer address
func ConnectWithPeerInfo ¶
ConnectWithPeerInfo Connects to a given peerInfo string
func Init ¶
func Init( root string, connManager ConnectionManager, discDriver DiscoveryDriver, advDriver AdvertisingDriver, hs WifiHotspot, con WifiConnection, ) error
Init Initialises the .datahop repo, if required at the given location with the given swarm port as config. Default swarm port is 4501
func InterfaceAddrs ¶
InterfaceAddrs returns a list of addresses at which this network listens. It expands "any interface" addresses (/ip4/0.0.0.0, /ip6/::) to use the known local interfaces.
func PeerInfo ¶
func PeerInfo() string
PeerInfo Returns a string of the peer.AddrInfo []byte of the node
func StartDiscovery ¶
func StartDiscovery() error
func StopDiscovery ¶
func StopDiscovery() error
func UpdateTopicStatus ¶
Types ¶
type AdvertisementNotifier ¶
type AdvertisementNotifier interface {
SameStatusDiscovered()
DifferentStatusDiscovered(topic string, value []byte)
}
func GetAdvertisementNotifier ¶
func GetAdvertisementNotifier() AdvertisementNotifier
type AdvertisingDriver ¶
type ConnectionManager ¶
ConnectionManager is used by clients to get notified client connection
type DiscoveryDriver ¶
type DiscoveryNotifier ¶
type DiscoveryNotifier interface {
PeerDiscovered(device string)
PeerSameStatusDiscovered(device string, topic string)
PeerDifferentStatusDiscovered(device string, topic string, network string, pass string, info string)
}
func GetDiscoveryNotifier ¶
func GetDiscoveryNotifier() DiscoveryNotifier
type Service ¶
func NewDiscoveryService ¶
func NewDiscoveryService( discDriver DiscoveryDriver, advDriver AdvertisingDriver, scanTime int, interval int, hs WifiHotspot, con WifiConnection, serviceTag string, ) (Service, error)
type WifiConnection ¶
type WifiConnectionNotifier ¶
type WifiConnectionNotifier interface {
OnConnectionSuccess()
OnConnectionFailure(code int)
OnDisconnect()
}
func GetWifiConnectionNotifier ¶
func GetWifiConnectionNotifier() WifiConnectionNotifier
type WifiHotspot ¶
type WifiHotspot interface {
Start() //(string, string)
Stop()
}
type WifiHotspotNotifier ¶
type WifiHotspotNotifier interface {
OnSuccess()
OnFailure(code int)
StopOnSuccess()
StopOnFailure(code int)
NetworkInfo(network string, password string)
ClientsConnected(num int)
}
func GetWifiHotspotNotifier ¶
func GetWifiHotspotNotifier() WifiHotspotNotifier