2019-06-18 11:56:11 +01:00
|
|
|
// Package network is a package for defining a network overlay
|
2019-06-17 16:57:53 +01:00
|
|
|
package network
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/micro/go-micro/config/options"
|
|
|
|
)
|
|
|
|
|
2019-06-18 11:56:11 +01:00
|
|
|
// Network is an interface defining networks or graphs
|
2019-06-17 16:57:53 +01:00
|
|
|
type Network interface {
|
|
|
|
options.Options
|
2019-06-18 11:56:11 +01:00
|
|
|
// Id of this node
|
|
|
|
Id() uint64
|
|
|
|
// Connect to a node
|
|
|
|
Connect(id uint64) (Link, error)
|
2019-06-17 16:57:53 +01:00
|
|
|
// Close the network connection
|
|
|
|
Close() error
|
2019-06-18 11:56:11 +01:00
|
|
|
// Accept messages on the network
|
2019-06-17 16:57:53 +01:00
|
|
|
Accept() (*Message, error)
|
2019-06-18 11:56:11 +01:00
|
|
|
// Send a message to the network
|
2019-06-17 16:57:53 +01:00
|
|
|
Send(*Message) error
|
2019-06-18 11:56:11 +01:00
|
|
|
// Retrieve list of connections
|
|
|
|
Links() ([]Link, error)
|
2019-06-17 16:57:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Node represents a network node
|
|
|
|
type Node interface {
|
2019-06-17 21:11:39 +01:00
|
|
|
// Node is a network. Network is a node.
|
|
|
|
Network
|
2019-06-17 16:57:53 +01:00
|
|
|
}
|
|
|
|
|
2019-06-18 11:56:11 +01: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 16:57:53 +01:00
|
|
|
}
|
2019-06-17 18:25:42 +01:00
|
|
|
|
2019-06-18 11:56:11 +01:00
|
|
|
// Message is the base type for opaque data
|
|
|
|
type Message []byte
|
|
|
|
|
2019-06-17 18:25:42 +01:00
|
|
|
var (
|
|
|
|
// TODO: set default network
|
|
|
|
DefaultNetwork Network
|
|
|
|
)
|