2019-08-05 19:04:47 +02:00
|
|
|
// Package network is for creating internetworks
|
|
|
|
package network
|
2019-08-20 13:48:51 +02:00
|
|
|
|
|
|
|
import (
|
2019-08-20 22:12:21 +02:00
|
|
|
"time"
|
|
|
|
|
2020-01-30 13:39:00 +02:00
|
|
|
"github.com/micro/go-micro/v2/client"
|
|
|
|
"github.com/micro/go-micro/v2/server"
|
2019-08-20 13:48:51 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
// DefaultName is default network name
|
2019-08-21 20:21:23 +02:00
|
|
|
DefaultName = "go.micro"
|
2019-08-20 13:48:51 +02:00
|
|
|
// DefaultAddress is default network address
|
|
|
|
DefaultAddress = ":0"
|
2019-08-28 21:11:19 +02:00
|
|
|
// ResolveTime defines time interval to periodically resolve network nodes
|
2019-08-20 22:12:21 +02:00
|
|
|
ResolveTime = 1 * time.Minute
|
2019-08-28 21:11:19 +02:00
|
|
|
// AnnounceTime defines time interval to periodically announce node neighbours
|
2019-12-13 17:27:47 +02:00
|
|
|
AnnounceTime = 1 * time.Second
|
|
|
|
// KeepAliveTime is the time in which we want to have sent a message to a peer
|
|
|
|
KeepAliveTime = 30 * time.Second
|
2020-01-10 21:02:42 +02:00
|
|
|
// SyncTime is the time a network node requests full sync from the network
|
2020-01-14 20:48:42 +02:00
|
|
|
SyncTime = 1 * time.Minute
|
2019-09-03 11:00:14 +02:00
|
|
|
// PruneTime defines time interval to periodically check nodes that need to be pruned
|
|
|
|
// due to their not announcing their presence within this time interval
|
|
|
|
PruneTime = 90 * time.Second
|
2019-08-20 13:48:51 +02:00
|
|
|
)
|
|
|
|
|
2020-01-14 20:12:36 +02:00
|
|
|
// Error is network node errors
|
|
|
|
type Error interface {
|
|
|
|
// Count is current count of errors
|
|
|
|
Count() int
|
|
|
|
// Msg is last error message
|
|
|
|
Msg() string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Status is node status
|
|
|
|
type Status interface {
|
|
|
|
// Error reports error status
|
|
|
|
Error() Error
|
|
|
|
}
|
|
|
|
|
2019-09-02 18:06:21 +02:00
|
|
|
// Node is network node
|
|
|
|
type Node interface {
|
|
|
|
// Id is node id
|
|
|
|
Id() string
|
|
|
|
// Address is node bind address
|
|
|
|
Address() string
|
2019-09-10 02:14:23 +02:00
|
|
|
// Peers returns node peers
|
|
|
|
Peers() []Node
|
2019-09-02 18:06:21 +02:00
|
|
|
// Network is the network node is in
|
|
|
|
Network() Network
|
2020-01-14 20:12:36 +02:00
|
|
|
// Status returns node status
|
|
|
|
Status() Status
|
2019-09-02 18:06:21 +02:00
|
|
|
}
|
|
|
|
|
2019-08-20 13:48:51 +02:00
|
|
|
// Network is micro network
|
|
|
|
type Network interface {
|
2019-09-02 13:39:26 +02:00
|
|
|
// Node is network node
|
|
|
|
Node
|
2019-10-13 13:38:13 +02:00
|
|
|
// Initialise options
|
|
|
|
Init(...Option) error
|
2019-09-02 12:42:45 +02:00
|
|
|
// Options returns the network options
|
|
|
|
Options() Options
|
2019-08-20 13:48:51 +02:00
|
|
|
// Name of the network
|
|
|
|
Name() string
|
|
|
|
// Connect starts the resolver and tunnel server
|
|
|
|
Connect() error
|
|
|
|
// Close stops the tunnel and resolving
|
|
|
|
Close() error
|
|
|
|
// Client is micro client
|
|
|
|
Client() client.Client
|
|
|
|
// Server is micro server
|
|
|
|
Server() server.Server
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewNetwork returns a new network interface
|
|
|
|
func NewNetwork(opts ...Option) Network {
|
|
|
|
return newNetwork(opts...)
|
|
|
|
}
|