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"
|
|
|
|
|
2019-08-20 13:48:51 +02:00
|
|
|
"github.com/micro/go-micro/client"
|
|
|
|
"github.com/micro/go-micro/server"
|
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
|
AnnounceTime = 30 * time.Second
|
2019-08-20 13:48:51 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// Network is micro network
|
|
|
|
type Network interface {
|
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
|
2019-08-21 20:16:18 +02:00
|
|
|
// Address returns network bind address
|
|
|
|
Address() string
|
2019-08-20 13:48:51 +02:00
|
|
|
// 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...)
|
|
|
|
}
|