Documentation ¶
Overview ¶
Package core provides an entry point to use Netools core functionalities.
Netools makes it possible to accept incoming network connections with certain protocol, process the data, and send them through another connection with the same or a difference protocol on demand.
It may be configured to work with multiple protocols at the same time, and uses the internal router to tunnel through different inbound and outbound connections.
Code generated by errors.codegen. DO NOT EDIT.
Index ¶
- Variables
- func AddInboundHandler(server *Instance, config *InboundHandlerConfig) error
- func AddOutboundHandler(server *Instance, config *OutboundHandlerConfig) error
- func CreateObject(v *Instance, config interface{}) (interface{}, error)
- func Dial(ctx context.Context, v *Instance, dest net.Destination) (net.Conn, error)
- func DialUDP(ctx context.Context, v *Instance) (net.PacketConn, error)
- func GetFormatByExtension(ext string) string
- func RegisterConfigLoader(format *ConfigFormat) error
- func RequireFeatures(ctx context.Context, callback interface{}) error
- func ServerType() interface{}
- func ToBackgroundDetachedContext(ctx context.Context) context.Context
- func Version() string
- func VersionStatement() []string
- type Config
- func (*Config) Descriptor() ([]byte, []int)deprecated
- func (x *Config) GetApp() []*serial.TypedMessage
- func (x *Config) GetExtension() []*serial.TypedMessage
- func (x *Config) GetInbound() []*InboundHandlerConfig
- func (x *Config) GetOutbound() []*OutboundHandlerConfig
- func (x *Config) GetTransport() *global.Configdeprecated
- func (*Config) ProtoMessage()
- func (x *Config) ProtoReflect() protoreflect.Message
- func (x *Config) Reset()
- func (x *Config) String() string
- type ConfigBuilder
- type ConfigFormat
- type ConfigLoader
- type InboundHandlerConfig
- func (*InboundHandlerConfig) Descriptor() ([]byte, []int)deprecated
- func (x *InboundHandlerConfig) GetProxySettings() *serial.TypedMessage
- func (x *InboundHandlerConfig) GetReceiverSettings() *serial.TypedMessage
- func (x *InboundHandlerConfig) GetTag() string
- func (*InboundHandlerConfig) ProtoMessage()
- func (x *InboundHandlerConfig) ProtoReflect() protoreflect.Message
- func (x *InboundHandlerConfig) Reset()
- func (x *InboundHandlerConfig) String() string
- type Instance
- func (s *Instance) AddFeature(feature features.Feature) error
- func (s *Instance) Close() error
- func (s *Instance) GetFeature(featureType interface{}) features.Feature
- func (s *Instance) RequireFeatures(callback interface{}) error
- func (s *Instance) Start() error
- func (s *Instance) Type() interface{}
- type NetoolKey
- type OutboundHandlerConfig
- func (*OutboundHandlerConfig) Descriptor() ([]byte, []int)deprecated
- func (x *OutboundHandlerConfig) GetComment() string
- func (x *OutboundHandlerConfig) GetExpire() int64
- func (x *OutboundHandlerConfig) GetProxySettings() *serial.TypedMessage
- func (x *OutboundHandlerConfig) GetSenderSettings() *serial.TypedMessage
- func (x *OutboundHandlerConfig) GetTag() string
- func (*OutboundHandlerConfig) ProtoMessage()
- func (x *OutboundHandlerConfig) ProtoReflect() protoreflect.Message
- func (x *OutboundHandlerConfig) Reset()
- func (x *OutboundHandlerConfig) String() string
- type Server
Constants ¶
This section is empty.
Variables ¶
var ( Version_x byte = 1 Version_y byte = 8 Version_z byte = 1 )
var File_core_config_proto protoreflect.FileDescriptor
Functions ¶
func AddInboundHandler ¶
func AddInboundHandler(server *Instance, config *InboundHandlerConfig) error
func AddOutboundHandler ¶
func AddOutboundHandler(server *Instance, config *OutboundHandlerConfig) error
func CreateObject ¶
CreateObject creates a new object based on the given Netool instance and config. The Netool instance may be nil.
func Dial ¶
Dial provides an easy way for upstream caller to create net.Conn through Netool. It dispatches the request to the given destination by the given Netool instance. Since it is under a proxy context, the LocalAddr() and RemoteAddr() in returned net.Conn will not show real addresses being used for communication.
netool:api:stable
func DialUDP ¶
DialUDP provides a way to exchange UDP packets through Netool instance to remote servers. Since it is under a proxy context, the LocalAddr() in returned PacketConn will not show the real address.
TODO: SetDeadline() / SetReadDeadline() / SetWriteDeadline() are not implemented.
netool:api:beta
func GetFormatByExtension ¶
func RegisterConfigLoader ¶
func RegisterConfigLoader(format *ConfigFormat) error
RegisterConfigLoader add a new ConfigLoader.
func RequireFeatures ¶
RequireFeatures is a helper function to require features from Instance in context. See Instance.RequireFeatures for more information.
func ToBackgroundDetachedContext ¶
ToBackgroundDetachedContext create a detached context from another context Internal API
func Version ¶
func Version() string
Version returns Netool's version as a string, in the form of "x.y.z" where x, y and z are numbers. ".z" part may be omitted in regular releases.
func VersionStatement ¶
func VersionStatement() []string
VersionStatement returns a list of strings representing the full version info.
Types ¶
type Config ¶
type Config struct { // Inbound handler configurations. Must have at least one item. Inbound []*InboundHandlerConfig `protobuf:"bytes,1,rep,name=inbound,proto3" json:"inbound,omitempty"` // Outbound handler configurations. Must have at least one item. The first // item is used as default for routing. Outbound []*OutboundHandlerConfig `protobuf:"bytes,2,rep,name=outbound,proto3" json:"outbound,omitempty"` // App is for configurations of all features in Netool. A feature must // implement the Feature interface, and its config type must be registered // through common.RegisterConfig. App []*serial.TypedMessage `protobuf:"bytes,4,rep,name=app,proto3" json:"app,omitempty"` // Transport settings. // Deprecated. Each inbound and outbound should choose their own transport // config. Date to remove: 2020-01-13 // // Deprecated: Marked as deprecated in core/config.proto. Transport *global.Config `protobuf:"bytes,5,opt,name=transport,proto3" json:"transport,omitempty"` // Configuration for extensions. The config may not work if corresponding // extension is not loaded into Netool. Netool will ignore such config during // initialization. Extension []*serial.TypedMessage `protobuf:"bytes,6,rep,name=extension,proto3" json:"extension,omitempty"` // contains filtered or unexported fields }
Config is the master config of Netool. Netool takes this config as input and functions accordingly.
func LoadConfig ¶
func (*Config) Descriptor
deprecated
func (*Config) GetApp ¶
func (x *Config) GetApp() []*serial.TypedMessage
func (*Config) GetExtension ¶
func (x *Config) GetExtension() []*serial.TypedMessage
func (*Config) GetInbound ¶
func (x *Config) GetInbound() []*InboundHandlerConfig
func (*Config) GetOutbound ¶
func (x *Config) GetOutbound() []*OutboundHandlerConfig
func (*Config) GetTransport
deprecated
func (*Config) ProtoMessage ¶
func (*Config) ProtoMessage()
func (*Config) ProtoReflect ¶
func (x *Config) ProtoReflect() protoreflect.Message
type ConfigBuilder ¶
ConfigBuilder is a builder to build core.Config from filenames and formats
var (
ConfigBuilderForFiles ConfigBuilder
)
type ConfigFormat ¶
type ConfigFormat struct { Name string Extension []string Loader ConfigLoader }
ConfigFormat is a configurable format of Netool config file.
type ConfigLoader ¶
ConfigLoader is a utility to load Netool config from external source.
type InboundHandlerConfig ¶
type InboundHandlerConfig struct { // Tag of the inbound handler. The tag must be unique among all inbound // handlers Tag string `protobuf:"bytes,1,opt,name=tag,proto3" json:"tag,omitempty"` // Settings for how this inbound proxy is handled. ReceiverSettings *serial.TypedMessage `protobuf:"bytes,2,opt,name=receiver_settings,json=receiverSettings,proto3" json:"receiver_settings,omitempty"` // Settings for inbound proxy. Must be one of the inbound proxies. ProxySettings *serial.TypedMessage `protobuf:"bytes,3,opt,name=proxy_settings,json=proxySettings,proto3" json:"proxy_settings,omitempty"` // contains filtered or unexported fields }
InboundHandlerConfig is the configuration for inbound handler.
func (*InboundHandlerConfig) Descriptor
deprecated
func (*InboundHandlerConfig) Descriptor() ([]byte, []int)
Deprecated: Use InboundHandlerConfig.ProtoReflect.Descriptor instead.
func (*InboundHandlerConfig) GetProxySettings ¶
func (x *InboundHandlerConfig) GetProxySettings() *serial.TypedMessage
func (*InboundHandlerConfig) GetReceiverSettings ¶
func (x *InboundHandlerConfig) GetReceiverSettings() *serial.TypedMessage
func (*InboundHandlerConfig) GetTag ¶
func (x *InboundHandlerConfig) GetTag() string
func (*InboundHandlerConfig) ProtoMessage ¶
func (*InboundHandlerConfig) ProtoMessage()
func (*InboundHandlerConfig) ProtoReflect ¶
func (x *InboundHandlerConfig) ProtoReflect() protoreflect.Message
func (*InboundHandlerConfig) Reset ¶
func (x *InboundHandlerConfig) Reset()
func (*InboundHandlerConfig) String ¶
func (x *InboundHandlerConfig) String() string
type Instance ¶
type Instance struct {
// contains filtered or unexported fields
}
Instance combines all functionalities in Netool.
func FromContext ¶
FromContext returns an Instance from the given context, or nil if the context doesn't contain one.
func MustFromContext ¶
MustFromContext returns an Instance from the given context, or panics if not present.
func New ¶
New returns a new Netool instance based on given configuration. The instance is not started at this point. To ensure Netool instance works properly, the config must contain one Dispatcher, one InboundHandlerManager and one OutboundHandlerManager. Other features are optional.
func StartInstance ¶
StartInstance starts a new Netool instance with given serialized config. By default Netool only support config in protobuf format, i.e., configFormat = "protobuf". Caller need to load other packages to add JSON support.
netool:api:stable
func (*Instance) AddFeature ¶
AddFeature registers a feature into current Instance.
func (*Instance) GetFeature ¶
GetFeature returns a feature of the given type, or nil if such feature is not registered.
func (*Instance) RequireFeatures ¶
RequireFeatures registers a callback, which will be called when all dependent features are registered. The callback must be a func(). All its parameters must be features.Feature.
type NetoolKey ¶
type NetoolKey int
NetoolKey is the key type of Instance in Context, exported for test.
type OutboundHandlerConfig ¶
type OutboundHandlerConfig struct { // Tag of this outbound handler. Tag string `protobuf:"bytes,1,opt,name=tag,proto3" json:"tag,omitempty"` // Settings for how to dial connection for this outbound handler. SenderSettings *serial.TypedMessage `protobuf:"bytes,2,opt,name=sender_settings,json=senderSettings,proto3" json:"sender_settings,omitempty"` // Settings for this outbound proxy. Must be one of the outbound proxies. ProxySettings *serial.TypedMessage `protobuf:"bytes,3,opt,name=proxy_settings,json=proxySettings,proto3" json:"proxy_settings,omitempty"` // If not zero, this outbound will be expired in seconds. Not used for now. Expire int64 `protobuf:"varint,4,opt,name=expire,proto3" json:"expire,omitempty"` // Comment of this outbound handler. Not used for now. Comment string `protobuf:"bytes,5,opt,name=comment,proto3" json:"comment,omitempty"` // contains filtered or unexported fields }
OutboundHandlerConfig is the configuration for outbound handler.
func (*OutboundHandlerConfig) Descriptor
deprecated
func (*OutboundHandlerConfig) Descriptor() ([]byte, []int)
Deprecated: Use OutboundHandlerConfig.ProtoReflect.Descriptor instead.
func (*OutboundHandlerConfig) GetComment ¶
func (x *OutboundHandlerConfig) GetComment() string
func (*OutboundHandlerConfig) GetExpire ¶
func (x *OutboundHandlerConfig) GetExpire() int64
func (*OutboundHandlerConfig) GetProxySettings ¶
func (x *OutboundHandlerConfig) GetProxySettings() *serial.TypedMessage
func (*OutboundHandlerConfig) GetSenderSettings ¶
func (x *OutboundHandlerConfig) GetSenderSettings() *serial.TypedMessage
func (*OutboundHandlerConfig) GetTag ¶
func (x *OutboundHandlerConfig) GetTag() string
func (*OutboundHandlerConfig) ProtoMessage ¶
func (*OutboundHandlerConfig) ProtoMessage()
func (*OutboundHandlerConfig) ProtoReflect ¶
func (x *OutboundHandlerConfig) ProtoReflect() protoreflect.Message
func (*OutboundHandlerConfig) Reset ¶
func (x *OutboundHandlerConfig) Reset()
func (*OutboundHandlerConfig) String ¶
func (x *OutboundHandlerConfig) String() string