micro/network/network.go

48 lines
986 B
Go
Raw Normal View History

2019-06-18 13:56:11 +03:00
// Package network is a package for defining a network overlay
2019-06-17 18:57:53 +03:00
package network
import (
"github.com/micro/go-micro/config/options"
)
2019-06-18 13:56:11 +03:00
// Network is an interface defining networks or graphs
2019-06-17 18:57:53 +03:00
type Network interface {
options.Options
2019-06-18 13:56:11 +03:00
// Id of this node
Id() uint64
// Connect to a node
Connect(id uint64) (Link, error)
2019-06-17 18:57:53 +03:00
// Close the network connection
Close() error
2019-06-18 13:56:11 +03:00
// Accept messages on the network
2019-06-17 18:57:53 +03:00
Accept() (*Message, error)
2019-06-18 13:56:11 +03:00
// Send a message to the network
2019-06-17 18:57:53 +03:00
Send(*Message) error
2019-06-18 13:56:11 +03:00
// Retrieve list of connections
Links() ([]Link, error)
2019-06-17 18:57:53 +03:00
}
// Node represents a network node
type Node interface {
2019-06-17 23:11:39 +03:00
// Node is a network. Network is a node.
Network
2019-06-17 18:57:53 +03:00
}
2019-06-18 13:56:11 +03:00
// Link is a connection to another node
type Link interface {
// remote node
Node
// length of link which dictates speed
Length() int
// weight of link which dictates curvature
Weight() int
2019-06-17 18:57:53 +03:00
}
2019-06-17 20:25:42 +03:00
2019-06-18 13:56:11 +03:00
// Message is the base type for opaque data
type Message []byte
2019-06-17 20:25:42 +03:00
var (
// TODO: set default network
DefaultNetwork Network
)