datahop

package
v0.0.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 14, 2021 License: Apache-2.0 Imports: 19 Imported by: 0

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

View Source
const (
	NoPeersConnected = "No Peers connected"
	CRDTStatus       = "datahop-crdt-status"
)
View Source
const ServiceTag = "_datahop-discovery._ble"

Variables

View Source
var (
	ErrNoPeersConnected = errors.New("no Peers connected")
	ErrNoPeerAddress    = errors.New("could not get peer address")
)

Functions

func Add

func Add(tag string, content []byte) error

Add adds a record in the store

func Addrs

func Addrs() ([]byte, error)

Addrs Returns a comma(,) separated string of all the possible addresses of a node

func Bootstrap

func Bootstrap(peerInfoByteString string) error

Bootstrap Connects to a given peerInfo string

func Close

func Close()

Close the repo and all

func ConnectWithAddress

func ConnectWithAddress(address string) error

ConnectWithAddress Connects to a given peer address

func ConnectWithPeerInfo

func ConnectWithPeerInfo(peerInfoByteString string) error

ConnectWithPeerInfo Connects to a given peerInfo string

func DiskUsage

func DiskUsage() (int64, error)

DiskUsage returns number of bytes stored in the datastore

func Get

func Get(tag string) ([]byte, error)

Get gets a record from the store by given tag

func GetTags

func GetTags() ([]byte, error)

GetTags gets all the tags from the store

func ID

func ID() string

ID Returns peerId of the node

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

func InterfaceAddrs() ([]byte, error)

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 IsNodeOnline

func IsNodeOnline() bool

IsNodeOnline Checks if the node is running

func PeerInfo

func PeerInfo() string

PeerInfo Returns a string of the peer.AddrInfo []byte of the node

func Peers

func Peers() ([]byte, error)

Peers Returns a comma(,) separated string of all the connected peers of a node

func Start

func Start(shouldBootstrap bool) error

Start an ipfslite node in a go routine

func StartDiscovery

func StartDiscovery() error

func State

func State() ([]byte, error)

State returns number of keys in crdt store

func Stop

func Stop()

Stop the node

func StopDiscovery

func StopDiscovery() error

func UpdateTopicStatus

func UpdateTopicStatus(topic string, value []byte)

func Version

func Version() string

Version of ipfs-lite

Types

type AdvertisementNotifier

type AdvertisementNotifier interface {
	SameStatusDiscovered()
	DifferentStatusDiscovered(topic string, value []byte)
}

func GetAdvertisementNotifier

func GetAdvertisementNotifier() AdvertisementNotifier

type AdvertisingDriver

type AdvertisingDriver interface {
	// Start the native driver
	Start(localPID string)
	AddAdvertisingInfo(topic string, info []byte)
	// Stop the native driver
	Stop()
	NotifyNetworkInformation(network string, pass string, info string)
	NotifyEmptyValue()
}

type ConnectionManager

type ConnectionManager interface {
	PeerConnected(string)
	PeerDisconnected(string)
}

ConnectionManager is used by clients to get notified client connection

type DiscoveryDriver

type DiscoveryDriver interface {
	// Start the native driver
	Start(localPID string, scanTime int, interval int)
	AddAdvertisingInfo(topic string, info []byte)
	// Stop the native driver
	Stop()
}

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 Notifee

type Notifee interface {
	HandlePeerFound(string)
}

type Notifier

type Notifier struct{}

func (*Notifier) ClosedStream

func (n *Notifier) ClosedStream(network.Network, network.Stream)

func (*Notifier) Connected

func (n *Notifier) Connected(net network.Network, c network.Conn)

func (*Notifier) Disconnected

func (n *Notifier) Disconnected(net network.Network, c network.Conn)

func (*Notifier) Listen

func (n *Notifier) Listen(network.Network, ma.Multiaddr)

func (*Notifier) ListenClose

func (n *Notifier) ListenClose(network.Network, ma.Multiaddr)

func (*Notifier) OpenedStream

func (n *Notifier) OpenedStream(net network.Network, s network.Stream)

type Service

type Service interface {
	io.Closer
	RegisterNotifee(Notifee)
	UnregisterNotifee(Notifee)
}

func NewDiscoveryService

func NewDiscoveryService(
	discDriver DiscoveryDriver,
	advDriver AdvertisingDriver,
	scanTime int,
	interval int,
	hs WifiHotspot,
	con WifiConnection,
	serviceTag string,
) (Service, error)

type WifiConnection

type WifiConnection interface {
	Connect(network string, pass string, ip string)
	Disconnect()
}

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL