whoson

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: May 31, 2022 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// SessionTimeOut is tcp session timeout limit.
	SessionTimeOut = 10 * time.Second
	// StoreDataExpire is stored data expire limit.
	StoreDataExpire = 30 * time.Minute
	// ExpireCheckInterval is expire check interval for stored data.
	ExpireCheckInterval = 5 * time.Minute
)

Variables

View Source
var (
	// MainStore holds main store.
	MainStore Store
	// Logger halds logging.
	Logger *zap.Logger
	// LogWriter is IO Writer.
	LogWriter reopen.Writer
	// IDGenerator halds id generator.
	IDGenerator katsubushi.Generator

	// ExpvarMap halds expvar map.
	ExpvarMap = expvar.NewMap("gowhoson")
)
View Source
var File_pkg_whoson_sync_proto protoreflect.FileDescriptor
View Source
var Sync_ServiceDesc = grpc.ServiceDesc{
	ServiceName: "whoson.sync",
	HandlerType: (*SyncServer)(nil),
	Methods: []grpc.MethodDesc{
		{
			MethodName: "Set",
			Handler:    _Sync_Set_Handler,
		},
		{
			MethodName: "Del",
			Handler:    _Sync_Del_Handler,
		},
		{
			MethodName: "Dump",
			Handler:    _Sync_Dump_Handler,
		},
	},
	Streams:  []grpc.StreamDesc{},
	Metadata: "pkg/whoson/sync.proto",
}

Sync_ServiceDesc is the grpc.ServiceDesc for Sync service. It's only intended for direct use with grpc.RegisterService, and not to be introspected or modified (even as a copy)

Functions

func InitLog

func InitLog(output, loglevel string) error

InitLog initial setup for Logger.

func ListenAndServe

func ListenAndServe(proto string, addr string) error

ListenAndServe simple start whoson server TCP or UDP.

func Log

func Log(status, msg string, ses *Session, err error)

Log is API entry point of Logging.

func NewIDGenerator

func NewIDGenerator(workerID uint) error

NewIDGenerator is set id generator to IDGenerator.

func NewLogger

func NewLogger(output, loglevel string) error

NewLogger return new zap.Logger struct pointer.

func NewMainStore

func NewMainStore()

NewMainStore set MemStore to MainStore.

func NewMainStoreEnableSyncRemote

func NewMainStoreEnableSyncRemote()

NewMainStoreEnableSyncRemote set MemStore to MainStore, enable sync remote.

func RegisterSyncServer

func RegisterSyncServer(s grpc.ServiceRegistrar, srv SyncServer)

func RunExpireChecker

func RunExpireChecker(ctx context.Context)

RunExpireChecker Check expire for all cmap store data.

func RunSyncRemote

func RunSyncRemote(ctx context.Context, hosts []string)

RunSyncRemote is sync data to remote grpc servers.

func ServeTCP

func ServeTCP(l *net.TCPListener) error

ServeTCP is start tcp server serve.

func ServeUDP

func ServeUDP(c *net.UDPConn) error

ServeUDP is start udp server serve.

Types

type Buffer

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

Buffer hold information for buffer pool.

func (*Buffer) Free

func (b *Buffer) Free()

Free push to buffer pool.

type BufferPool

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

BufferPool hold information for sync.Pool.

func NewBufferPool

func NewBufferPool() *BufferPool

NewBufferPool return new BufferPool struct pointer.

func (*BufferPool) Get

func (p *BufferPool) Get() *Buffer

Get get from buffer pool.

type Client

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

Client hold information for whoson API client.

func Dial

func Dial(proto string, addr string) (*Client, error)

Dial creates a new client connection.

func NewClient

func NewClient(conn net.Conn, host string) (*Client, error)

NewClient return new Client struct pointer and error.

func (*Client) Close

func (c *Client) Close() error

Close closes the connection.

func (*Client) Login

func (c *Client) Login(ip string, args string) (*Response, error)

Login access to LOGIN API.

func (*Client) Logout

func (c *Client) Logout(ip string) (*Response, error)

Logout access to LOGOUT API.

func (*Client) Query

func (c *Client) Query(ip string) (*Response, error)

Query access to QUERY API.

func (*Client) Quit

func (c *Client) Quit() (*Response, error)

Quit access to QUIT API.

type ClientConfig

type ClientConfig struct {
	Mode   string
	Server string
}

ClientConfig hold information for client configration.

type MemStore

type MemStore struct {
	SyncRemote bool
	Store
	// contains filtered or unexported fields
}

MemStore hold information for cmap.

func (MemStore) Count

func (ms MemStore) Count() int

Count return all data size.

func (MemStore) Del

func (ms MemStore) Del(k string) bool

Del delete data from cmap store.

func (MemStore) Get

func (ms MemStore) Get(k string) (*StoreData, error)

Get data from cmap store.

func (MemStore) Items

func (ms MemStore) Items() map[string]interface{}

Items return all data from cmap store.

func (MemStore) ItemsJSON

func (ms MemStore) ItemsJSON() ([]byte, error)

ItemsJSON return all data of json format.

func (MemStore) Set

func (ms MemStore) Set(k string, w *StoreData)

Set data to cmap store.

func (MemStore) SyncDel

func (ms MemStore) SyncDel(k string) bool

SyncDel data from remote host store.

func (MemStore) SyncSet

func (ms MemStore) SyncSet(k string, w *StoreData)

SyncSet data to remote host store.

type MethodType

type MethodType int

MethodType is whoson protocol methods.

type ProtocolType

type ProtocolType int

ProtocolType is whoson protocol types.

type Response

type Response struct {
	Msg string
	// contains filtered or unexported fields
}

Response hold information for response values.

func (*Response) Parse

func (r *Response) Parse(req string) error

Parse set values for Response.

func (*Response) String

func (r *Response) String() string

type ResultType

type ResultType int

ResultType is whoson protocol results.

type ServerConfig

type ServerConfig struct {
	TCP         string
	UDP         string
	Log         string
	Loglevel    string
	ServerID    int
	Expvar      bool
	ControlPort string
	SyncRemote  string
	SaveFile    string
}

ServerConfig hold information for server configration.

type ServerCtl

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

ServerCtl hold information for server control.

func NewServerCtl

func NewServerCtl(server string) *ServerCtl

NewServerCtl return new ServerCtl struct pointer.

func (*ServerCtl) Dump

func (sc *ServerCtl) Dump() error

Dump Set grpc repository to sc.dumpResp

func (*ServerCtl) SetWriter

func (sc *ServerCtl) SetWriter(o io.Writer)

SetWriter Set io.Writer to sc.out

func (*ServerCtl) WriteJSON

func (sc *ServerCtl) WriteJSON() error

WriteJSON Output json with io.Writer

func (*ServerCtl) WriteTable

func (sc *ServerCtl) WriteTable() error

WriteTable Output Table with io.Writer

type ServerCtlConfig

type ServerCtlConfig struct {
	Server     string
	JSON       bool
	EditConfig bool
}

ServerCtlConfig hold information for serverctl configration.

type Session

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

Session hold information for whoson session.

func NewSessionTCP

func NewSessionTCP(s *TCPServer, c net.Conn) (*Session, error)

NewSessionTCP return new Session struct pointer for TCP.

func NewSessionUDP

func NewSessionUDP(c *net.UDPConn, r *net.UDPAddr, b *Buffer) (*Session, error)

NewSessionUDP return new Session struct pointer for UDP.

type Store

type Store interface {
	Set(k string, w *StoreData)
	Get(k string) (*StoreData, error)
	Del(k string) bool
	Items() map[string]interface{}
	ItemsJSON() ([]byte, error)
	Count() int
	SyncSet(k string, w *StoreData)
	SyncDel(k string) bool
}

Store is hold Store API.

func NewMemStore

func NewMemStore() Store

NewMemStore return new MemStore.

type StoreData

type StoreData struct {
	Expire time.Time
	IP     net.IP
	Data   string
}

StoreData hold information for whoson data.

func (*StoreData) Key

func (sd *StoreData) Key() string

Key return key string.

func (*StoreData) UpdateExpire

func (sd *StoreData) UpdateExpire()

UpdateExpire Update stored data of expire time.

type Sync

type Sync struct {
	UnimplementedSyncServer
}

Sync hold information for synchronization.

func (*Sync) Del

func (s *Sync) Del(c context.Context, wreq *WSRequest) (*WSResponse, error)

Del delete to repliction servers

func (*Sync) Dump

func (s *Sync) Dump(c context.Context, wreq *WSDumpRequest) (*WSDumpResponse, error)

Dump dump to all data

func (*Sync) Set

func (s *Sync) Set(c context.Context, wreq *WSRequest) (*WSResponse, error)

Set sync to repliction servers

type SyncClient

type SyncClient interface {
	Set(ctx context.Context, in *WSRequest, opts ...grpc.CallOption) (*WSResponse, error)
	Del(ctx context.Context, in *WSRequest, opts ...grpc.CallOption) (*WSResponse, error)
	Dump(ctx context.Context, in *WSDumpRequest, opts ...grpc.CallOption) (*WSDumpResponse, error)
}

SyncClient is the client API for Sync service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.

func NewSyncClient

func NewSyncClient(cc grpc.ClientConnInterface) SyncClient

type SyncServer

type SyncServer interface {
	Set(context.Context, *WSRequest) (*WSResponse, error)
	Del(context.Context, *WSRequest) (*WSResponse, error)
	Dump(context.Context, *WSDumpRequest) (*WSDumpResponse, error)
	// contains filtered or unexported methods
}

SyncServer is the server API for Sync service. All implementations must embed UnimplementedSyncServer for forward compatibility

type TCPServer

type TCPServer struct {
	Addr string
	// contains filtered or unexported fields
}

TCPServer hold information for tcp server.

func NewTCPServer

func NewTCPServer() *TCPServer

NewTCPServer return new TCPServer struct pointer.

func (*TCPServer) ListenAndServe

func (s *TCPServer) ListenAndServe() error

ListenAndServe simple start tcp server.

func (*TCPServer) ServeTCP

func (s *TCPServer) ServeTCP(l *net.TCPListener) error

ServeTCP is start tcp server serve

type UDPServer

type UDPServer struct {
	Addr string
	// contains filtered or unexported fields
}

UDPServer hold information for udp server.

func NewUDPServer

func NewUDPServer() *UDPServer

NewUDPServer return new UDPServer struct pointer.

func (*UDPServer) ListenAndServe

func (s *UDPServer) ListenAndServe() error

ListenAndServe simple start udp server.

func (*UDPServer) ServeUDP

func (s *UDPServer) ServeUDP(c *net.UDPConn) error

ServeUDP is start udp server serve.

type UnimplementedSyncServer added in v0.2.7

type UnimplementedSyncServer struct {
}

UnimplementedSyncServer must be embedded to have forward compatible implementations.

func (UnimplementedSyncServer) Del added in v0.2.7

func (UnimplementedSyncServer) Dump added in v0.2.7

func (UnimplementedSyncServer) Set added in v0.2.7

type UnsafeSyncServer added in v0.2.7

type UnsafeSyncServer interface {
	// contains filtered or unexported methods
}

UnsafeSyncServer may be embedded to opt out of forward compatibility for this service. Use of this interface is not recommended, as added methods to SyncServer will result in compilation errors.

type WSDumpRequest

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

func (*WSDumpRequest) Descriptor deprecated

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

Deprecated: Use WSDumpRequest.ProtoReflect.Descriptor instead.

func (*WSDumpRequest) ProtoMessage

func (*WSDumpRequest) ProtoMessage()

func (*WSDumpRequest) ProtoReflect added in v0.2.7

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

func (*WSDumpRequest) Reset

func (x *WSDumpRequest) Reset()

func (*WSDumpRequest) String

func (x *WSDumpRequest) String() string

type WSDumpResponse

type WSDumpResponse struct {
	Rcode int32  `protobuf:"varint,1,opt,name=Rcode,proto3" json:"Rcode,omitempty"`
	Msg   string `protobuf:"bytes,2,opt,name=Msg,proto3" json:"Msg,omitempty"`
	Json  []byte `protobuf:"bytes,3,opt,name=Json,proto3" json:"Json,omitempty"`
	// contains filtered or unexported fields
}

func (*WSDumpResponse) Descriptor deprecated

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

Deprecated: Use WSDumpResponse.ProtoReflect.Descriptor instead.

func (*WSDumpResponse) GetJson added in v0.2.7

func (x *WSDumpResponse) GetJson() []byte

func (*WSDumpResponse) GetMsg added in v0.2.7

func (x *WSDumpResponse) GetMsg() string

func (*WSDumpResponse) GetRcode added in v0.2.7

func (x *WSDumpResponse) GetRcode() int32

func (*WSDumpResponse) ProtoMessage

func (*WSDumpResponse) ProtoMessage()

func (*WSDumpResponse) ProtoReflect added in v0.2.7

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

func (*WSDumpResponse) Reset

func (x *WSDumpResponse) Reset()

func (*WSDumpResponse) String

func (x *WSDumpResponse) String() string

type WSRequest

type WSRequest struct {
	Expire int64  `protobuf:"varint,1,opt,name=Expire,proto3" json:"Expire,omitempty"`
	IP     string `protobuf:"bytes,2,opt,name=IP,proto3" json:"IP,omitempty"`
	Data   string `protobuf:"bytes,3,opt,name=Data,proto3" json:"Data,omitempty"`
	Method string `protobuf:"bytes,4,opt,name=Method,proto3" json:"Method,omitempty"`
	// contains filtered or unexported fields
}

func (*WSRequest) Descriptor deprecated

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

Deprecated: Use WSRequest.ProtoReflect.Descriptor instead.

func (*WSRequest) GetData added in v0.2.7

func (x *WSRequest) GetData() string

func (*WSRequest) GetExpire added in v0.2.7

func (x *WSRequest) GetExpire() int64

func (*WSRequest) GetIP added in v0.2.7

func (x *WSRequest) GetIP() string

func (*WSRequest) GetMethod added in v0.2.7

func (x *WSRequest) GetMethod() string

func (*WSRequest) ProtoMessage

func (*WSRequest) ProtoMessage()

func (*WSRequest) ProtoReflect added in v0.2.7

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

func (*WSRequest) Reset

func (x *WSRequest) Reset()

func (*WSRequest) String

func (x *WSRequest) String() string

type WSResponse

type WSResponse struct {
	Rcode int32  `protobuf:"varint,1,opt,name=Rcode,proto3" json:"Rcode,omitempty"`
	Msg   string `protobuf:"bytes,2,opt,name=Msg,proto3" json:"Msg,omitempty"`
	// contains filtered or unexported fields
}

func (*WSResponse) Descriptor deprecated

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

Deprecated: Use WSResponse.ProtoReflect.Descriptor instead.

func (*WSResponse) GetMsg added in v0.2.7

func (x *WSResponse) GetMsg() string

func (*WSResponse) GetRcode added in v0.2.7

func (x *WSResponse) GetRcode() int32

func (*WSResponse) ProtoMessage

func (*WSResponse) ProtoMessage()

func (*WSResponse) ProtoReflect added in v0.2.7

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

func (*WSResponse) Reset

func (x *WSResponse) Reset()

func (*WSResponse) String

func (x *WSResponse) String() string

type Worker

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

Worker hold information for udp server processing workers.

func (*Worker) Run

func (w *Worker) Run(ctx context.Context)

Run start worker processing.

Jump to

Keyboard shortcuts

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