service

package
v0.0.0-...-fa7aae8 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2020 License: AGPL-3.0 Imports: 20 Imported by: 0

README

service

This folder contains all the services used to start IPFS, configure it and interact with Onet.

clusterbootstrap.go

This file contains the ClusterBootstrapProtocol. This protocol is called is called by the protocol StartIPFSProtocol, and is run for each ARA on the leader, this one will start an IPFS Cluster instance, and communicate its bootstrap address to all the other members of the ARA. The other members will start an IPFS Cluster instance with the bootstrap address of the leader to join the ARA.

const.go

This file contains the constants used in the service folder.

helpers.go

This file contains helpers methods used in the service folder. Most of the methods directly interact with the os, for instance creating directory or getting an unused port.

ipfs.go

This file contains all the code setting up IPFS and IPFS Cluster daemons, and starting them.

ping.go

This file contains the code used to compute the ping distances between the hosts. The ping distances can be computed: each host ping every other host in the system and then, they share their distances to all other hosts with all peers in the system. The ping distance between each pair of hosts can also be loaded from a text file.

service.go

This file contains the Onet service. The Setup service initializes all the data structures, computes ping distances and builds the ARAs.

startara.go

This file contains the protocol StartARAProtocol. This protocol is called by StartInstancesProtocol on the root of an ARA. It starts an IPFS daemon, then an IPFS Cluster daemon on the ARA leader, and then broadcast its bootstrap address to all other cluster members that will join the cluster using this bootstrap address. The other cluster members will also start one new IPFS and one new IPFS Cluster instance to join the ARA.

startinstances.go

This file contains the protocol StartInstancesProtocol. This protocol is called on the root of the Onet tree, and for each ARA calls the protocol StartARAProtocol, in order to start one IPFS and IPFS Cluster daemon for each ARA membership on each node.

startipfs.go

This file contains the protocol StartIPFSProtocol. This protocol is run on the root of the Onet tree, and starts a single IPFS daemon on each host. Each host return its IPFS bootstrap address to the leader. Then this protocol start an instance of ClusterBootstrapProtocol for each ARA on the ARA leader.

struct.go

This file contains the structures used in the service folder.

Documentation

Index

Constants

View Source
const (
	// ClusterConsensusMode "raft" or "crdt"
	ClusterConsensusMode = "raft"

	// DefaultReplMin ipfs cluster minimal replication factor
	DefaultReplMin = 2
	// DefaultReplMax ipfs cluster maximal replication factor
	DefaultReplMax = 2

	// BaseHostPort first port allocated to a node
	BaseHostPort = 14000

	// IPVersion default ip version
	IPVersion = "/ip4/"
	// TransportProtocol default transport protocol
	TransportProtocol = "/tcp/"

	// MaxPortNumberPerHost max number of ports that a host can use
	MaxPortNumberPerHost = 200
	// IPFSPortNumber number of ports used by an IPFS instance
	IPFSPortNumber = 3
	// ClusterPortNumber number of ports used by an ipfs cluster instance
	ClusterPortNumber = 3

	// IPFSStartupTime IPFSStartupTime
	IPFSStartupTime = 13 * time.Second
	// ClusterStartupTime ClusterStartupTime
	ClusterStartupTime = 2 * time.Second

	// ConfigsFolder folder name
	ConfigsFolder = "configs"
	// IPFSFolder ipfs config folder name
	IPFSFolder = "ipfs"
	// ClusterFolderPrefix prefix of cluster configs folder name
	ClusterFolderPrefix = "cluster-"

	// NodeName name of a node instance
	NodeName = "node_"
	// Node0 name of the first node
	Node0 = NodeName + "0"

	// ServiceName name of the service
	ServiceName = "IPFS"

	// StartIPFSName name of StartIPFS protocol
	StartIPFSName = "StartIPFS"
	// ClusterBootstrapName name of ClusterBootstrap protocol
	ClusterBootstrapName = "ClusterBootstrap"
	// StartARAName name of the StartARA protocol
	StartARAName = "StartARA"
	// StartInstancesName name of the StartInstancesName protocol
	StartInstancesName = "StartInstances"

	// PingsFile File with stored pings
	PingsFile = "../pings.txt"
)

Variables

This section is empty.

Functions

func CreateEmptyDir

func CreateEmptyDir(path string) error

CreateEmptyDir create an empty directory at the given path

func EditIPFSField

func EditIPFSField(path, field, value string)

EditIPFSField with the native IPFS config command

func GetClusterVariables

func GetClusterVariables(path, ip, secret, peername, apiIPFSAddr string,
	replmin, replmax int, ports ClusterInstance) string

GetClusterVariables get the cluster variables

func GetEnvVar

func GetEnvVar(field, value string) string

GetEnvVar get the environnment variable for the given field and value

func GetNextAvailablePorts

func GetNextAvailablePorts(pmin, pmax, n int) (*[]int, error)

GetNextAvailablePorts return n available ports between pmin and pmax crash if error

func MakeJSONArray

func MakeJSONArray(elements []string) string

MakeJSONArray make a json array from the given elements

func MakeJSONElem

func MakeJSONElem(elem string) string

MakeJSONElem make a JSON single element

func NewClusterBootstrapProtocol

func NewClusterBootstrapProtocol(n *onet.TreeNodeInstance, getServ FnService) (
	onet.ProtocolInstance, error)

NewClusterBootstrapProtocol initialises the structure for use in one round

func NewStartARAProtocol

func NewStartARAProtocol(n *onet.TreeNodeInstance, getServ FnService) (
	onet.ProtocolInstance, error)

NewStartARAProtocol initialises the structure for use in one round

func NewStartIPFSProtocol

func NewStartIPFSProtocol(n *onet.TreeNodeInstance, getServ FnService) (
	onet.ProtocolInstance, error)

NewStartIPFSProtocol initialises the structure for use in one round

func NewStartInstancesProtocol

func NewStartInstancesProtocol(n *onet.TreeNodeInstance, getServ FnService) (
	onet.ProtocolInstance, error)

NewStartInstancesProtocol initialises the structure for use in one round

func ReadConfig

func ReadConfig(file string) (string, error)

ReadConfig read a config file given as parameter and returns a string

func ReadFileLineByLine

func ReadFileLineByLine(configFilePath string) func() string

ReadFileLineByLine reads a file line by line

func WriteConfig

func WriteConfig(path string, config string) error

WriteConfig write string to a file

Types

type ClusterBootstrapAnnounce

type ClusterBootstrapAnnounce struct {
	SenderName string
	Bootstrap  string
	Secret     string
}

ClusterBootstrapAnnounce is used to pass a message to all children.

type ClusterBootstrapProtocol

type ClusterBootstrapProtocol struct {
	*onet.TreeNodeInstance

	Ready      chan bool
	Info       ClusterInfo
	GetService FnService
	// contains filtered or unexported fields
}

ClusterBootstrapProtocol structure

func (*ClusterBootstrapProtocol) Dispatch

func (p *ClusterBootstrapProtocol) Dispatch() error

Dispatch implements the main logic of the protocol. The function is only called once. The protocol is considered finished when Dispatch returns and Done is called.

func (*ClusterBootstrapProtocol) Start

func (p *ClusterBootstrapProtocol) Start() error

Start sends the Announce-message to all children

type ClusterBootstrapReply

type ClusterBootstrapReply struct {
	Cluster *[]ClusterInstance
}

ClusterBootstrapReply returns true when ready.

type ClusterInfo

type ClusterInfo struct {
	Leader    string
	Secret    string
	Size      int
	Instances []ClusterInstance
}

ClusterInfo information about a given cluster

type ClusterInstance

type ClusterInstance struct {
	HostName      string
	IP            string
	IPFSAPIAddr   string
	RestAPIPort   int
	IPFSProxyPort int
	ClusterPort   int
}

ClusterInstance details of a cluster

type FnService

type FnService func() *Service

FnService function that returns the service of that node

type IPFSInformation

type IPFSInformation struct {
	Name        string
	IP          string
	SwarmPort   int
	APIPort     int
	GatewayPort int
}

IPFSInformation structure containing information about an IPFS instance

type InitRequest

type InitRequest struct {
	Nodes                []*gentree.LocalityNode
	ServerIdentityToName map[*network.ServerIdentity]string
	OnetTree             *onet.Tree
	Roster               *onet.Roster
	Cruxified            bool
	ComputePings         bool
	Mode                 string
}

InitRequest packet

type InitResponse

type InitResponse struct {
}

InitResponse packet

type NodeInfo

type NodeInfo struct {
	IPFS     IPFSInformation
	Clusters []ClusterInfo
}

NodeInfo contains ipfs and ipfs-cluster information for a given node

type ReplyPings

type ReplyPings struct {
	Pings      string
	SenderName string
}

ReplyPings reply packet for ping service

type ReqPings

type ReqPings struct {
	SenderName string
}

ReqPings request packet for ping service

type Service

type Service struct {
	// We need to embed the ServiceProcessor, so that incoming messages
	// are correctly handled.
	*onet.ServiceProcessor

	Nodes        gentree.LocalityNodes
	LocalityTree *onet.Tree
	Parents      []*onet.TreeNode
	GraphTree    map[string][]gentree.GraphTree
	BinaryTree   map[string][]*onet.Tree

	Distances map[*gentree.LocalityNode]map[*gentree.LocalityNode]float64

	PortMutex *sync.Mutex
	W         *bufio.Writer
	File      *os.File

	BandwidthRx uint64
	BandwidthTx uint64
	NrMsgRx     uint64
	NrMsgTx     uint64

	NrProtocolsStarted uint64

	OwnPings      map[string]float64
	DonePing      bool
	PingDistances map[string]map[string]float64
	NrPingAnswers int
	PingAnswerMtx sync.Mutex
	PingMapMtx    sync.Mutex

	Name       string // name of the service (node_2)
	MyIP       string // IP address
	ConfigPath string // path to home config folder
	MyIPFSPath string // path to ipfs config folder of that service
	MinPort    int    // port range allocated to this node
	MaxPort    int
	MyIPFS     []IPFSInformation          // own ipfs information
	OtherIPFS  map[string]IPFSInformation // node_x -> IP, ports etc.

	OnetTree      *onet.Tree
	StartIPFSProt onet.ProtocolInstance
	// contains filtered or unexported fields
}

Service is our template-service

func (*Service) EditIPFSConfig

func (s *Service) EditIPFSConfig(path string) string

EditIPFSConfig edit the ipfs configuration file (mainly the ip) returns the API address of the IPFS instance

func (*Service) ExecReplyPings

func (s *Service) ExecReplyPings(env *network.Envelope) error

ExecReplyPings handle replies of other nodes ping distances to get the full array of distances between each nodes

func (*Service) ExecReqPings

func (s *Service) ExecReqPings(env *network.Envelope) error

ExecReqPings sends all its own pings distances to the node that requested it

func (*Service) GetService

func (s *Service) GetService() *Service

GetService Returns the Current SERVICE

func (*Service) InitRequest

func (s *Service) InitRequest(req *InitRequest) (
	*InitResponse, error)

InitRequest init the tree

func (*Service) NewProtocol

func (s *Service) NewProtocol(tn *onet.TreeNodeInstance,
	conf *onet.GenericConfig) (onet.ProtocolInstance, error)

NewProtocol is called on all nodes of a Tree (except the root, since it is the one starting the protocol) so it's the Service that will be called to generate the PI on all others node. If you use CreateProtocolOnet, this will not be called, as the Onet will instantiate the protocol on its own. If you need more control at the instantiation of the protocol, use CreateProtocolService, and you can give some extra-configuration to your protocol in here.

func (*Service) PrintName

func (s *Service) PrintName()

PrintName PrintName

func (*Service) SetClusterLeaderConfig

func (s *Service) SetClusterLeaderConfig(path, apiIPFSAddr string,
	replmin, replmax int, ports ClusterInstance) (
	string, string, error)

SetClusterLeaderConfig set the configs for the leader of a cluster

func (*Service) SetupClusterLeader

func (s *Service) SetupClusterLeader(path, secret, apiIPFSAddr string,
	replmin, replmax int) (string, *ClusterInstance, error)

SetupClusterLeader setup a cluster instance for the ARA leader

func (*Service) SetupClusterSlave

func (s *Service) SetupClusterSlave(path, bootstrap, secret, apiIPFSAddr string,
	replmin, replmax int) (*ClusterInstance, error)

SetupClusterSlave setup a cluster slave instance

func (*Service) StartIPFS

func (s *Service) StartIPFS(secret string) string

StartIPFS starts an IPFS instance for the given service return the multiaddress of the IPFS API

func (*Service) StartIPFSAndCluster

func (s *Service) StartIPFSAndCluster(leader, secret,
	bootstrap string) *ClusterInstance

StartIPFSAndCluster starts an IPFS instance along with the cluster instance empty secret means that this instance is the cluster leader if leader, returns secret and the started instance information containing bootstrap address for slaves

type StartARAAnnounce

type StartARAAnnounce struct {
	SenderName string
	Bootstrap  string
	Secret     string
}

StartARAAnnounce is used to pass a message to all children.

type StartARAProtocol

type StartARAProtocol struct {
	*onet.TreeNodeInstance

	Ready      chan bool
	Info       ClusterInfo
	GetService FnService
	// contains filtered or unexported fields
}

StartARAProtocol structure

func (*StartARAProtocol) Dispatch

func (p *StartARAProtocol) Dispatch() error

Dispatch implements the main logic of the protocol. The function is only called once. The protocol is considered finished when Dispatch returns and Done is called.

func (*StartARAProtocol) Start

func (p *StartARAProtocol) Start() error

Start sends the Announce-message to all children

type StartARAReply

type StartARAReply struct {
	Cluster *[]ClusterInstance
}

StartARAReply returns true when ready.

type StartIPFSAnnounce

type StartIPFSAnnounce struct {
	Message string
}

StartIPFSAnnounce is used to pass a message to all children.

type StartIPFSProtocol

type StartIPFSProtocol struct {
	*onet.TreeNodeInstance

	Ready      chan bool
	GetService FnService
	Nodes      map[string]*NodeInfo
	// contains filtered or unexported fields
}

StartIPFSProtocol structure

func (*StartIPFSProtocol) Dispatch

func (p *StartIPFSProtocol) Dispatch() error

Dispatch implements the main logic of the protocol. The function is only called once. The protocol is considered finished when Dispatch returns and Done is called.

func (*StartIPFSProtocol) Start

func (p *StartIPFSProtocol) Start() error

Start sends the Announce-message to all children

type StartIPFSReply

type StartIPFSReply struct {
	IPFS     *IPFSInformation
	Clusters *[]ClusterInfo
}

StartIPFSReply returns true when ready.

type StartInstancesAnnounce

type StartInstancesAnnounce struct{}

StartInstancesAnnounce is used to pass a message to all children.

type StartInstancesProtocol

type StartInstancesProtocol struct {
	*onet.TreeNodeInstance

	Ready      chan bool
	GetService FnService
	Nodes      map[string]*NodeInfo
	// contains filtered or unexported fields
}

StartInstancesProtocol structure

func (*StartInstancesProtocol) Dispatch

func (p *StartInstancesProtocol) Dispatch() error

Dispatch implements the main logic of the protocol. The function is only called once. The protocol is considered finished when Dispatch returns and Done is called.

func (*StartInstancesProtocol) Start

func (p *StartInstancesProtocol) Start() error

Start sends the Announce-message to all children

type StartInstancesReply

type StartInstancesReply struct {
	Node *NodeInfo
}

StartInstancesReply returns true when ready.

Jump to

Keyboard shortcuts

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