From e1ecd728c59558999430a3654de6a236013cb5f7 Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Mon, 5 Aug 2019 17:52:57 +0100 Subject: [PATCH] Adds outline of go-micro Tunnel interface --- tunnel/options.go | 63 +++++++++++++++++++++++++++++++++++++++++++++++ tunnel/tunnel.go | 15 +++++++++++ 2 files changed, 78 insertions(+) create mode 100644 tunnel/options.go create mode 100644 tunnel/tunnel.go diff --git a/tunnel/options.go b/tunnel/options.go new file mode 100644 index 00000000..86db722e --- /dev/null +++ b/tunnel/options.go @@ -0,0 +1,63 @@ +package tunnel + +import ( + "github.com/google/uuid" + "github.com/micro/go-micro/transport" +) + +var ( + // DefaultAddress is default tunnel bind address + DefaultAddress = ":9096" +) + +type Option func(*Options) + +// Options provides network configuration options +type Options struct { + // Id is tunnel id + Id string + // Address is tunnel address + Address string + // Nodes are remote nodes + Nodes []string + // Transport listens to incoming connections + Transport transport.Transport +} + +// The tunnel id +func Id(id string) Option { + return func(o *Options) { + o.Id = id + } +} + +// The tunnel address +func Address(a string) Option { + return func(o *Options) { + o.Address = a + } +} + +// Nodes specify remote network nodes +func Nodes(n []string) Option { + return func(o *Options) { + o.Nodes = n + } +} + +// Transport listens for incoming connections +func Transport(t transport.Transport) Option { + return func(o *Options) { + o.Transport = t + } +} + +// DefaultOptions returns router default options +func DefaultOptions() Options { + return Options{ + Id: uuid.New().String(), + Address: DefaultAddress, + Nodes: make([]string, 0), + Transport: transport.DefaultTransport, + } +} diff --git a/tunnel/tunnel.go b/tunnel/tunnel.go new file mode 100644 index 00000000..e208157b --- /dev/null +++ b/tunnel/tunnel.go @@ -0,0 +1,15 @@ +// Package tunnel provides micro network tunnelling +package tunnel + +import ( + "github.com/micro/go-micro/transport" +) + +// Tunnel creates a p2p network tunnel. +type Tunnel interface { + transport.Transport + // Connect connects the tunnel + Connect() error + // Close closes the tunnel + Close() error +}