traffic

package
v0.7.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2022 License: Apache-2.0 Imports: 17 Imported by: 1

README

traffic

描述:io 通信控制模块

  • 管理所有的需要热重启的监听管理(端口监听)
  • 只允许master执行新增,序列化成描述信息+文件描述符列表
  • 在fork worker时传递给worker
  • worker只允许使用传入进来的端口

用法

// master
// 首次启动
tf, err := traffic.ReadController(os.stdint, &net.TCPAddr{
IP:   "0.0.0.0",
Port: 8080,
})
// 导出
traffics, files := tf.Export(3)
trafficsData, err := proto.Marshal(&traffic.PbTraffics{Traffic: traffics})
// 新进程
cmd := exec.Command(path)
cmd.Stdin = bytes.NewReader(data)
cmd.SysProcAttr = &syscall.SysProcAttr{
Setsid: true,
}
cmd.ExtraFiles = files


// 热重启,新进程,会在复用的前提下监听新的tcpAddr列表,并关闭不再使用的listener
traffic, err := traffic.ReadController(os.stdint, &net.TCPAddr{
IP:   "0.0.0.0",
Port: 8080,
},
&net.TCPAddr{ // 新增端口
IP:   "0.0.0.0",
Port: 9090,
})

//worker 中
trafficConfigs = read from os.Stdin
tf:=traffic.NewTraffic(tfConf)

// 启用服务

l := tf.ListenTcp(port, traffic.Http1)
if l == nil {
    panic(fmt.SprintF("port:%s is not listener",port))
}

err:=http.Serve(l,handler)


Documentation

Overview

  • Copyright (c) 2021. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
  • Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
  • Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
  • Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
  • Vestibulum commodo. Ut rhoncus gravida arcu. *

io 通信控制模块 管理所有的需要热重启的监听管理(端口监听), 只允许master执行新增, 序列化成描述信息+文件描述符列表,在fork worker时传递给worker, worker只允许使用传入进来的端口

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorInvalidListener = errors.New("invalid port-reqiure")
)
View Source
var File_traffic_proto protoreflect.FileDescriptor

Functions

This section is empty.

Types

type Controller

type Controller struct {
	*Traffic
}

func (*Controller) Export added in v0.3.0

func (c *Controller) Export(startIndex int) ([]*PbTraffic, []*os.File)

func (*Controller) Shutdown added in v0.7.0

func (c *Controller) Shutdown()

type EmptyTraffic added in v0.5.0

type EmptyTraffic struct {
}

func NewEmptyTraffic added in v0.5.0

func NewEmptyTraffic() *EmptyTraffic

func (*EmptyTraffic) Close added in v0.5.0

func (e *EmptyTraffic) Close()

func (*EmptyTraffic) IsStop added in v0.5.0

func (e *EmptyTraffic) IsStop() bool

func (*EmptyTraffic) ListenTcp added in v0.5.0

func (e *EmptyTraffic) ListenTcp(port int, trafficType TrafficType) net.Listener

type IController

type IController interface {
	ITraffic
	Shutdown()
	//Reset(ports []int) (isCreate bool, err error)
	Export(int) ([]*PbTraffic, []*os.File)
}

func ReadController added in v0.7.0

func ReadController(r io.Reader, addr ...*net.TCPAddr) (IController, error)

type ITraffic

type ITraffic interface {
	ListenTcp(port int, trafficType TrafficType) net.Listener
	IsStop() bool
	Close()
}

type Matcher added in v0.7.0

type Matcher struct {
	cmuxMatch.CMuxMatch
	// contains filtered or unexported fields
}

func NewMatcher added in v0.7.0

func NewMatcher(port int, ls ...*net.TCPListener) *Matcher

func (*Matcher) Close added in v0.7.0

func (m *Matcher) Close() error

func (*Matcher) Listeners added in v0.7.0

func (m *Matcher) Listeners() []*net.TCPListener

type MatcherData added in v0.7.0

type MatcherData struct {
	// contains filtered or unexported fields
}

func NewMatcherData added in v0.7.0

func NewMatcherData(tfConf ...*PbTraffic) *MatcherData

func (*MatcherData) All added in v0.7.0

func (m *MatcherData) All() map[int]*Matcher

func (*MatcherData) Clone added in v0.7.0

func (m *MatcherData) Clone() *MatcherData

func (*MatcherData) Del added in v0.7.0

func (m *MatcherData) Del(port int) (*Matcher, bool)

func (*MatcherData) Get added in v0.7.0

func (m *MatcherData) Get(port int) *Matcher

func (*MatcherData) Set added in v0.7.0

func (m *MatcherData) Set(port int, mux *Matcher)

type PbTraffic

type PbTraffic struct {
	FD      uint64 `protobuf:"varint,1,opt,name=FD,proto3" json:"FD,omitempty"`
	Addr    string `protobuf:"bytes,2,opt,name=Addr,proto3" json:"Addr,omitempty"`
	Network string `protobuf:"bytes,3,opt,name=Network,proto3" json:"Network,omitempty"`
	// contains filtered or unexported fields
}

func (*PbTraffic) Descriptor deprecated

func (*PbTraffic) Descriptor() ([]byte, []int)

Deprecated: Use PbTraffic.ProtoReflect.Descriptor instead.

func (*PbTraffic) GetAddr

func (x *PbTraffic) GetAddr() string

func (*PbTraffic) GetFD

func (x *PbTraffic) GetFD() uint64

func (*PbTraffic) GetNetwork

func (x *PbTraffic) GetNetwork() string

func (*PbTraffic) ProtoMessage

func (*PbTraffic) ProtoMessage()

func (*PbTraffic) ProtoReflect

func (x *PbTraffic) ProtoReflect() protoreflect.Message

func (*PbTraffic) Reset

func (x *PbTraffic) Reset()

func (*PbTraffic) String

func (x *PbTraffic) String() string

type PbTraffics

type PbTraffics struct {
	Traffic []*PbTraffic `protobuf:"bytes,1,rep,name=traffic,proto3" json:"traffic,omitempty"`
	// contains filtered or unexported fields
}

func (*PbTraffics) Descriptor deprecated

func (*PbTraffics) Descriptor() ([]byte, []int)

Deprecated: Use PbTraffics.ProtoReflect.Descriptor instead.

func (*PbTraffics) GetTraffic

func (x *PbTraffics) GetTraffic() []*PbTraffic

func (*PbTraffics) ProtoMessage

func (*PbTraffics) ProtoMessage()

func (*PbTraffics) ProtoReflect

func (x *PbTraffics) ProtoReflect() protoreflect.Message

func (*PbTraffics) Reset

func (x *PbTraffics) Reset()

func (*PbTraffics) String

func (x *PbTraffics) String() string

type Traffic

type Traffic struct {
	// contains filtered or unexported fields
}

func NewTraffic

func NewTraffic(traffics []*PbTraffic) *Traffic

func (*Traffic) Close

func (t *Traffic) Close()

func (*Traffic) IsStop added in v0.5.0

func (t *Traffic) IsStop() bool

func (*Traffic) ListenTcp

func (t *Traffic) ListenTcp(port int, trafficType TrafficType) net.Listener

type TrafficType added in v0.7.0

type TrafficType = cmuxMatch.MatchType
const (
	Any TrafficType = iota
	Http1
	Https
	Http2
	Websocket
	GRPC
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL