1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-06 08:16:03 +02:00
go-micro/network/network.go

76 lines
1.5 KiB
Go
Raw Normal View History

2019-06-18 12:56:11 +02:00
// Package network is a package for defining a network overlay
2019-06-17 17:57:53 +02:00
package network
import (
"github.com/micro/go-micro/config/options"
)
2019-06-22 17:51:20 +02:00
// Network is an interface defining a network
2019-06-17 17:57:53 +02:00
type Network interface {
options.Options
2019-06-18 12:56:11 +02:00
// Id of this node
2019-06-22 17:51:20 +02:00
Id() string
// Connect to the network
Connect() (Node, error)
// Peer with a neighboring network
Peer(Network) (Link, error)
2019-06-18 12:56:11 +02:00
// Retrieve list of connections
Links() ([]Link, error)
2019-06-17 17:57:53 +02:00
}
2019-06-22 17:51:20 +02:00
// Node represents a single node on a network
2019-06-17 17:57:53 +02:00
type Node interface {
2019-06-17 22:11:39 +02:00
// Node is a network. Network is a node.
Network
2019-06-22 20:02:57 +02:00
// Address of the node
Address() string
// Close the network connection
Close() error
// Accept messages on the network
Accept() (*Message, error)
// Send a message to the network
Send(*Message) error
2019-06-17 17:57:53 +02:00
}
2019-06-22 17:51:20 +02:00
// Link is a connection between one network and another
2019-06-18 12:56:11 +02:00
type Link interface {
2019-06-22 17:51:20 +02:00
// remote node the link is to
2019-06-18 12:56:11 +02:00
Node
// length of link which dictates speed
Length() int
// weight of link which dictates curvature
Weight() int
2019-06-17 17:57:53 +02:00
}
2019-06-17 19:25:42 +02:00
2019-06-18 12:56:11 +02:00
// Message is the base type for opaque data
2019-06-22 17:51:20 +02:00
type Message struct {
// Headers which provide local/remote info
Header map[string]string
// The opaque data being sent
Data []byte
}
2019-06-18 12:56:11 +02:00
2019-06-17 19:25:42 +02:00
var (
// The default network ID is local
DefaultNetworkId = "local"
// just the standard network element
DefaultNetwork = NewNetwork()
2019-06-17 19:25:42 +02:00
)
// NewNetwork returns a new network
func NewNetwork(opts ...options.Option) Network {
options := options.NewOptions(opts...)
// get router
// get proxy
return &network{
Options: options,
// fill the blanks
// router: r,
// proxy: p,
}
}