Documentation ¶
Overview ¶
owtp全称OpenWallet Transfer Protocol,OpenWallet的一种点对点的分布式私有通信协议。
owtp全称OpenWallet Transfer Protocol,OpenWallet的一种点对点的分布式私有通信协议。
Index ¶
- Constants
- Variables
- func GenerateRangeNum(min, max int) int
- func HttpListenAddr(addr string, enableSignature bool, handler PeerHandler) (*httpListener, error)
- func NewOWTPPeerstore() *owtpPeerstore
- func RandomPrivateKey() string
- func WSListenAddr(addr string, cert Certificate, enableSignature bool, handler PeerHandler) (*wsListener, error)
- type Authorization
- type AuthorizationBase
- func (base *AuthorizationBase) DecryptData(data []byte, key []byte) ([]byte, error)
- func (base *AuthorizationBase) EnableAuth() bool
- func (base *AuthorizationBase) EnableKeyAgreement() bool
- func (base *AuthorizationBase) EncryptData(data []byte, key []byte) ([]byte, error)
- func (base *AuthorizationBase) GenerateSignature(data *DataPacket) bool
- func (base *AuthorizationBase) InitKeyAgreement(keyAgreement *KeyAgreement) error
- func (base *AuthorizationBase) RequestKeyAgreement(keyAgreement *KeyAgreement) error
- func (base *AuthorizationBase) ResponseKeyAgreement(keyAgreement *KeyAgreement) error
- func (base *AuthorizationBase) VerifyKeyAgreement(keyAgreement *KeyAgreement) bool
- func (base *AuthorizationBase) VerifySignature(data *DataPacket) bool
- type Certificate
- type ConnectConfig
- type ConnectType
- type Context
- func (ctx *Context) DelSession(name string)
- func (ctx *Context) DestroySession()
- func (ctx *Context) GetSession(name string) interface{}
- func (ctx *Context) Params() gjson.Result
- func (ctx *Context) Response(result interface{}, status uint64, msg string)
- func (ctx *Context) ResponseStopRun(result interface{}, status uint64, msg string)
- func (ctx *Context) SetSession(name string, value interface{})
- type DataPacket
- type HTTPClient
- func HTTPDial(pid, url string, handler PeerHandler, header map[string]string, ...) (*HTTPClient, error)
- func NewHTTPClient(pid string, responseWriter http.ResponseWriter, request *http.Request, ...) (*HTTPClient, error)
- func NewHTTPClientWithHeader(responseWriter http.ResponseWriter, request *http.Request, hander PeerHandler, ...) (*HTTPClient, error)
- type HandlerFunc
- type KeyAgreement
- type Listener
- type MQClient
- type MqAddr
- type NodeConfig
- type OWTPAuth
- func (auth *OWTPAuth) DecryptData(data []byte, key []byte) ([]byte, error)
- func (auth *OWTPAuth) EnableAuth() bool
- func (auth *OWTPAuth) EnableKeyAgreement() bool
- func (auth *OWTPAuth) EncryptData(data []byte, key []byte) ([]byte, error)
- func (auth *OWTPAuth) GenerateSignature(data *DataPacket) bool
- func (auth *OWTPAuth) HTTPAuthHeader() map[string]string
- func (auth *OWTPAuth) InitKeyAgreement(keyAgreement *KeyAgreement) error
- func (auth *OWTPAuth) LocalPID() string
- func (auth *OWTPAuth) RemotePID() string
- func (auth *OWTPAuth) RequestKeyAgreement(keyAgreement *KeyAgreement) error
- func (auth *OWTPAuth) ResponseKeyAgreement(keyAgreement *KeyAgreement) error
- func (auth *OWTPAuth) VerifyKeyAgreement(keyAgreement *KeyAgreement) bool
- func (auth *OWTPAuth) VerifySignature(data *DataPacket) bool
- type OWTPNode
- func (node *OWTPNode) AddOnlinePeer(peer Peer)
- func (node *OWTPNode) Call(pid string, method string, params interface{}, sync bool, reqFunc RequestFunc) error
- func (node *OWTPNode) CallSync(pid string, method string, params interface{}) (*Response, error)
- func (node *OWTPNode) Certificate() *Certificate
- func (node *OWTPNode) Close()
- func (node *OWTPNode) CloseListener(connectType string)
- func (node *OWTPNode) ClosePeer(pid string)
- func (node *OWTPNode) Connect(pid string, config ConnectConfig) error
- func (node *OWTPNode) ConnectAndCall(pid string, config ConnectConfig, method string, params interface{}, sync bool, ...) error
- func (node *OWTPNode) GetOnlinePeer(id string) Peer
- func (node *OWTPNode) GetValueForPeer(peer Peer, key string) interface{}
- func (node *OWTPNode) HandleFinishFunc(handler HandlerFunc)
- func (node *OWTPNode) HandleFunc(method string, handler HandlerFunc)
- func (node *OWTPNode) HandlePrepareFunc(handler HandlerFunc)
- func (node *OWTPNode) IsConnectPeer(pid string) bool
- func (node *OWTPNode) KeyAgreement(pid string, consultType string) error
- func (node *OWTPNode) Listen(config ConnectConfig) error
- func (node *OWTPNode) Listening(connectType string) bool
- func (node *OWTPNode) NodeID() string
- func (node *OWTPNode) OnPeerClose(peer Peer, reason string)
- func (node *OWTPNode) OnPeerNewDataPacketReceived(peer Peer, packet *DataPacket)
- func (node *OWTPNode) OnPeerOpen(peer Peer)
- func (node *OWTPNode) OnlinePeers() []Peer
- func (node *OWTPNode) Peerstore() Peerstore
- func (node *OWTPNode) PutValueForPeer(peer Peer, key string, val interface{}) error
- func (node *OWTPNode) RemoveOfflinePeer(id string)
- func (node *OWTPNode) Run() error
- func (node *OWTPNode) SetCloseHandler(h func(n *OWTPNode, peer PeerInfo))
- func (node *OWTPNode) SetOpenHandler(h func(n *OWTPNode, peer PeerInfo))
- func (node *OWTPNode) SetPeerstore(store Peerstore)
- type Param
- type Peer
- type PeerAttribute
- type PeerHandler
- type PeerInfo
- type Peerstore
- type RequestFunc
- type RequestQueue
- type Response
- type SecretData
- type ServeMux
- func (mux *ServeMux) AddRequest(peer Peer, nonce uint64, time int64, method string, reqFunc RequestFunc, ...) error
- func (mux *ServeMux) HandleFunc(method string, handler HandlerFunc)
- func (mux *ServeMux) RemoveRequest(pid string, nonce uint64) error
- func (mux *ServeMux) ResetRequestQueue(pid string)
- func (mux *ServeMux) ServeOWTP(pid string, ctx *Context)
- type SessionManager
- func (store *SessionManager) Delete(id string, key string) error
- func (store *SessionManager) Destroy(id string) error
- func (store *SessionManager) GC()
- func (store *SessionManager) Get(id string, key string) interface{}
- func (store *SessionManager) GetActiveSession() int
- func (store *SessionManager) GetProvider() session.Provider
- func (store *SessionManager) GetSessionStore(pid string) (sessions session.Store, err error)
- func (store *SessionManager) GetString(id string, key string) string
- func (store *SessionManager) PeerInfo(id string) PeerInfo
- func (store *SessionManager) Put(id string, key string, val interface{}) error
- func (store *SessionManager) SavePeer(peer Peer)
- func (store *SessionManager) SessionDestroy(pid string)
- type WSClient
- func Dial(pid, url string, handler PeerHandler, header map[string]string, ...) (*WSClient, error)
- func NewWSClient(pid string, conn *websocket.Conn, handler PeerHandler, auth Authorization, ...) (*WSClient, error)
- func NewWSClientWithHeader(header http.Header, cert Certificate, conn *websocket.Conn, ...) (*WSClient, error)
Constants ¶
const ( WSRequest = 1 //请求标识 WSResponse = 2 //响应标识 )
const ( //成功标识 StatusSuccess uint64 = 200 //客户端请求错误 ErrBadRequest uint64 = 400 ErrUnauthorized uint64 = 401 //通信密钥不正确 ErrSecretKeyInvalid uint64 = 402 //找不到方法 ErrNotFoundMethod uint64 = 404 //重放攻击 ErrReplayAttack uint64 = 409 //重放攻击 ErrRequestTimeout uint64 = 408 //网络断开 ErrNetworkDisconnected uint64 = 430 //服务器错误 ErrInternalServerError uint64 = 500 //请求与响应的方法不一致 ErrResponseMethodDiffer uint64 = 501 //协商失败 ErrKeyAgreementFailed uint64 = 502 //拒绝服务 ErrDenialOfService uint64 = 503 //60X: 自定义错误 ErrCustomError uint64 = 600 )
const ( Websocket string = "ws" MQ string = "mq" HTTP string = "http" )
连接方式
const ( //校验协商结果 KeyAgreementMethod = "internal_keyAgreement" //准备前执行的方 PrepareMethod = "internal_prepare" //结束时执行的方法 FinishMethod = "internal_finish" )
内置方法
const ( WriteWait = 60 * time.Second PongWait = 30 * time.Second PingPeriod = (PongWait * 9) / 10 MaxMessageSize = 1 * 1024 )
局部常量
const (
DefaultTimoutSEC = 60
)
Variables ¶
var (
Debug = false
)
Functions ¶
func HttpListenAddr ¶
func HttpListenAddr(addr string, enableSignature bool, handler PeerHandler) (*httpListener, error)
ListenAddr 创建OWTP协议通信监听
func WSListenAddr ¶
func WSListenAddr(addr string, cert Certificate, enableSignature bool, handler PeerHandler) (*wsListener, error)
WSListenAddr 创建websocket通信监听
Types ¶
type Authorization ¶
type Authorization interface { //EnableAuth 开启授权 EnableAuth() bool //GenerateSignature 生成签名,并把签名加入到DataPacket中 GenerateSignature(data *DataPacket) bool //VerifySignature 校验签名,若验证错误,可更新错误信息到DataPacket中 VerifySignature(data *DataPacket) bool //EnableKeyAgreement 开启密码协商 EnableKeyAgreement() bool //InitKeyAgreement 发起协商 InitKeyAgreement(keyAgreement *KeyAgreement) error //RequestKeyAgreement 请求协商,计算密钥 RequestKeyAgreement(keyAgreement *KeyAgreement) error //ResponseKeyAgreement 响应协商,计算密钥 ResponseKeyAgreement(keyAgreement *KeyAgreement) error //VerifyKeyAgreement 验证协商结果 VerifyKeyAgreement(keyAgreement *KeyAgreement) bool //EncryptData 加密数据 EncryptData(data []byte, key []byte) ([]byte, error) //DecryptData 解密数据 DecryptData(data []byte, key []byte) ([]byte, error) }
Authorization 授权
type AuthorizationBase ¶
type AuthorizationBase struct{}
func (*AuthorizationBase) DecryptData ¶
func (base *AuthorizationBase) DecryptData(data []byte, key []byte) ([]byte, error)
DecryptData 解密数据
func (*AuthorizationBase) EnableAuth ¶
func (base *AuthorizationBase) EnableAuth() bool
EnableAuth 开启授权
func (*AuthorizationBase) EnableKeyAgreement ¶
func (base *AuthorizationBase) EnableKeyAgreement() bool
EnableKeyAgreement 开启密码协商
func (*AuthorizationBase) EncryptData ¶
func (base *AuthorizationBase) EncryptData(data []byte, key []byte) ([]byte, error)
EncryptData 加密数据
func (*AuthorizationBase) GenerateSignature ¶
func (base *AuthorizationBase) GenerateSignature(data *DataPacket) bool
GenerateSignature 生成签名,并把签名加入到DataPacket中
func (*AuthorizationBase) InitKeyAgreement ¶
func (base *AuthorizationBase) InitKeyAgreement(keyAgreement *KeyAgreement) error
InitKeyAgreement 发起协商
func (*AuthorizationBase) RequestKeyAgreement ¶
func (base *AuthorizationBase) RequestKeyAgreement(keyAgreement *KeyAgreement) error
RequestKeyAgreement 请求协商,计算密钥
func (*AuthorizationBase) ResponseKeyAgreement ¶
func (base *AuthorizationBase) ResponseKeyAgreement(keyAgreement *KeyAgreement) error
ResponseKeyAgreement 响应协商,计算密钥
func (*AuthorizationBase) VerifyKeyAgreement ¶
func (base *AuthorizationBase) VerifyKeyAgreement(keyAgreement *KeyAgreement) bool
VerifyKeyAgreement 是否完成密码协商,验证协商结果
func (*AuthorizationBase) VerifySignature ¶
func (base *AuthorizationBase) VerifySignature(data *DataPacket) bool
VerifySignature 校验签名,若验证错误,可更新错误信息到DataPacket中
type Certificate ¶
type Certificate struct {
// contains filtered or unexported fields
}
func NewCertificate ¶
func NewCertificate(privateKey string, consultType ...string) (Certificate, error)
func (*Certificate) ID ¶
func (cert *Certificate) ID() string
func (*Certificate) KeyPair ¶
func (cert *Certificate) KeyPair() (priv string, pub string)
func (*Certificate) PrivateKeyBytes ¶
func (cert *Certificate) PrivateKeyBytes() []byte
func (*Certificate) PublicKeyBytes ¶
func (cert *Certificate) PublicKeyBytes() []byte
type ConnectConfig ¶
type ConnectConfig struct { Address string `json:"address"` //@required 连接IP地址 ConnectType string `json:"connectType"` //@required 连接方式 EnableSignature bool `json:"enableSignature"` //是否开启owtp协议内签名,防重放 Account string `json:"account"` //mq账户名 Password string `json:"password"` //mq账户密码 Exchange string `json:"exchange"` //mq需要字段 WriteQueueName string `json:"writeQueueName"` //mq写入通道名 ReadQueueName string `json:"readQueueName"` //mq读取通道名 EnableSSL bool `json:"enableSSL"` //是否开启链接SSL,https,wss ReadBufferSize int `json:"readBufferSize"` //socket读取缓存 WriteBufferSize int `json:"writeBufferSize"` //socket写入缓存 }
节点主配置 作为json解析工具
type ConnectType ¶
type ConnectType int
type Context ¶
type Context struct { //节点ID PID string //传输类型,1:请求,2:响应 Req uint64 //请求的远程IP RemoteAddress string //方法 Method string //响应 Resp Response //节点指针 Peer Peer // contains filtered or unexported fields }
func NewContext ¶
NewContext
func (*Context) DelSession ¶
DelSession removes value from session.
func (*Context) DestroySession ¶
func (ctx *Context) DestroySession()
DestroySession cleans session data
func (*Context) GetSession ¶
GetSession gets value from session.
func (*Context) ResponseStopRun ¶
ResponseStopRun 中断操作,Context.stop = true,将不再执行后面的绑定的业务 并完成Response处理
func (*Context) SetSession ¶
SetSession puts value into session.
type DataPacket ¶
type DataPacket struct { Req uint64 `json:"r"` Method string `json:"m"` Nonce uint64 `json:"n" storm:"id"` Timestamp int64 `json:"t"` Data interface{} `json:"d"` Signature string `json:"s"` SecretData SecretData `json:"k"` }
DataPacket 数据包
func NewDataPacket ¶
func NewDataPacket(json gjson.Result) *DataPacket
NewDataPacket 通过 gjson转为DataPacket
type HTTPClient ¶
type HTTPClient struct { ReadBufferSize int WriteBufferSize int // contains filtered or unexported fields }
HTTPClient 基于http的通信服务端
func HTTPDial ¶
func HTTPDial( pid, url string, handler PeerHandler, header map[string]string, timeout time.Duration) (*HTTPClient, error)
func NewHTTPClient ¶
func NewHTTPClient(pid string, responseWriter http.ResponseWriter, request *http.Request, hander PeerHandler, auth Authorization) (*HTTPClient, error)
func NewHTTPClientWithHeader ¶
func NewHTTPClientWithHeader(responseWriter http.ResponseWriter, request *http.Request, hander PeerHandler, enableSignature bool) (*HTTPClient, error)
func (*HTTPClient) ConnectConfig ¶
func (c *HTTPClient) ConnectConfig() ConnectConfig
func (*HTTPClient) IsConnected ¶
func (c *HTTPClient) IsConnected() bool
func (*HTTPClient) IsHost ¶
func (c *HTTPClient) IsHost() bool
func (*HTTPClient) PID ¶
func (c *HTTPClient) PID() string
type KeyAgreement ¶
type KeyAgreement struct { EncryptType string //协商密码类型 PublicKeyInitiator string //发送方:本地公钥 PrivateKeyInitiator string //发送方:本地私钥 TmpPublicKeyInitiator string //发送方:临时公钥 TmpPrivateKeyInitiator string //发送方:临时私钥 PublicKeyResponder string //响应方:本地公钥 PrivateKeyResponder string //响应方:本地私钥 TmpPublicKeyResponder string //响应方:临时公钥 TmpPrivateKeyResponder string //响应方:临时私钥 S2 string //响应方:本地验证码,RequestKeyAgreement生成 SB string //响应方:生成协商密码的必要验证码,RequestKeyAgreement生成 SA string //发送方:本地验证码,ResponseKeyAgreement生成 Key string //协商的密钥 }
KeyAgreement 协商密码
type MQClient ¶
type MQClient struct { ReadBufferSize int WriteBufferSize int // contains filtered or unexported fields }
MQClient 基于mq的通信客户端
func MQDial ¶
func MQDial(pid, url string, handler PeerHandler) (*MQClient, error)
Dial connects a client to the given URL.
func NewMQClient ¶
func NewMQClient(pid string, conn *amqp.Connection, channel *amqp.Channel, hander PeerHandler, auth Authorization, done func()) (*MQClient, error)
func (*MQClient) ConnectConfig ¶
func (c *MQClient) ConnectConfig() ConnectConfig
func (*MQClient) IsConnected ¶
type NodeConfig ¶
type NodeConfig struct { TimeoutSEC int `json:"timeoutSEC"` //超时时间 Cert Certificate `json:"cert"` //证书 Peerstore Peerstore //会话缓存 }
节点主配置 作为json解析工具
type OWTPAuth ¶
type OWTPAuth struct { AuthorizationBase // contains filtered or unexported fields }
Authorization 授权
func NewOWTPAuthWithCertificate ¶
func NewOWTPAuthWithCertificate(cert Certificate, enable bool) (*OWTPAuth, error)
func (*OWTPAuth) DecryptData ¶
DecryptData 解密数据
func (*OWTPAuth) EnableKeyAgreement ¶
EnableKeyAgreement 开启密码协商
func (*OWTPAuth) EncryptData ¶
EncryptData 加密数据
func (*OWTPAuth) GenerateSignature ¶
func (auth *OWTPAuth) GenerateSignature(data *DataPacket) bool
GenerateSignature 生成签名,并把签名加入到DataPacket中
func (*OWTPAuth) HTTPAuthHeader ¶
AuthHeader 返回授权头
func (*OWTPAuth) InitKeyAgreement ¶
func (auth *OWTPAuth) InitKeyAgreement(keyAgreement *KeyAgreement) error
InitKeyAgreement 发起协商
func (*OWTPAuth) RequestKeyAgreement ¶
func (auth *OWTPAuth) RequestKeyAgreement(keyAgreement *KeyAgreement) error
RequestKeyAgreement 请求协商
func (*OWTPAuth) ResponseKeyAgreement ¶
func (auth *OWTPAuth) ResponseKeyAgreement(keyAgreement *KeyAgreement) error
ResponseKeyAgreement 响应协商
func (*OWTPAuth) VerifyKeyAgreement ¶
func (auth *OWTPAuth) VerifyKeyAgreement(keyAgreement *KeyAgreement) bool
func (*OWTPAuth) VerifySignature ¶
func (auth *OWTPAuth) VerifySignature(data *DataPacket) bool
VerifySignature 校验签名,若验证错误,可更新错误信息到DataPacket中
type OWTPNode ¶
type OWTPNode struct { //Broadcast chan BroadcastMessage Join chan Peer Leave chan Peer Stop chan struct{} // contains filtered or unexported fields }
OWTPNode 实现OWTP协议的节点
func NewOWTPNode ¶
func NewOWTPNode(cert Certificate, readBufferSize, writeBufferSize int) *OWTPNode
NewOWTPNode 创建OWTP协议节点
func (*OWTPNode) AddOnlinePeer ¶
AddOnlinePeer 添加在线节点
func (*OWTPNode) Call ¶
func (node *OWTPNode) Call( pid string, method string, params interface{}, sync bool, reqFunc RequestFunc) error
Call 向对方节点进行调用
func (*OWTPNode) CloseListener ¶
CloseListener 关闭监听
func (*OWTPNode) Connect ¶
func (node *OWTPNode) Connect(pid string, config ConnectConfig) error
Connect 建立长连接
func (*OWTPNode) ConnectAndCall ¶
func (node *OWTPNode) ConnectAndCall( pid string, config ConnectConfig, method string, params interface{}, sync bool, reqFunc RequestFunc) error
ConnectAndCall 通过连接配置并直接请求,如果节点在线使用当前连接请求
func (*OWTPNode) GetOnlinePeer ¶
GetOnlinePeer 获取当前在线的Peer
func (*OWTPNode) GetValueForPeer ¶
func (*OWTPNode) HandleFinishFunc ¶
func (node *OWTPNode) HandleFinishFunc(handler HandlerFunc)
HandleFinishFunc 绑定结束后的处理方法
func (*OWTPNode) HandleFunc ¶
func (node *OWTPNode) HandleFunc(method string, handler HandlerFunc)
HandleFunc 绑定路由器方法
func (*OWTPNode) HandlePrepareFunc ¶
func (node *OWTPNode) HandlePrepareFunc(handler HandlerFunc)
HandlePrepareFunc 绑定准备前的处理方法
func (*OWTPNode) IsConnectPeer ¶
IsConnectPeer 是否连接某个节点
func (*OWTPNode) KeyAgreement ¶
KeyAgreement 发起协商请求 这是一个同步请求
func (*OWTPNode) OnPeerClose ¶
OnPeerClose 节点关闭
func (*OWTPNode) OnPeerNewDataPacketReceived ¶
func (node *OWTPNode) OnPeerNewDataPacketReceived(peer Peer, packet *DataPacket)
OnPeerNewDataPacketReceived 节点获取新数据包
func (*OWTPNode) PutValueForPeer ¶
func (*OWTPNode) RemoveOfflinePeer ¶
RemoveOfflinePeer 移除不在线的节点
func (*OWTPNode) SetCloseHandler ¶
SetCloseHandler 设置关闭连接时的回调
func (*OWTPNode) SetOpenHandler ¶
SetCloseHandler 设置关闭连接时的回调
func (*OWTPNode) SetPeerstore ¶
SetPeerstore 设置一个Peerstore指针
type Peer ¶
type Peer interface { PID() string //节点ID IsHost() bool //是否主机,我方主动连接的节点 IsConnected() bool //是否已经连接 LocalAddr() net.Addr //本地节点地址 RemoteAddr() net.Addr //远程节点地址 ConnectConfig() ConnectConfig // 返回配置信息 // contains filtered or unexported methods }
Peer 节点
type PeerAttribute ¶
type PeerAttribute map[string]interface{}
type PeerHandler ¶
type PeerHandler interface { OnPeerOpen(peer Peer) //节点连接成功 OnPeerClose(peer Peer, reason string) //节点关闭 OnPeerNewDataPacketReceived(peer Peer, packet *DataPacket) //节点获取新数据包 GetValueForPeer(peer Peer, key string) interface{} PutValueForPeer(peer Peer, key string, val interface{}) error }
PeerHandler 节点监听器
type PeerInfo ¶
type PeerInfo struct { ID string Config ConnectConfig }
type Peerstore ¶
type Peerstore interface { // SaveAddr 保存节点地址 SavePeer(peer Peer) //PeerInfo 节点信息 PeerInfo(id string) PeerInfo // Get 获取节点属性 Get(id string, key string) interface{} // GetString GetString(id string, key string) string // Put 设置节点属性 Put(id string, key string, val interface{}) error // Delete 设置节点属性 Delete(id string, key string) error //Destroy 清空store数据 Destroy(id string) error }
Peerstore 节点存储器
type Response ¶
type SecretData ¶
type SecretData struct { PublicKeyInitiator string `json:"pk"` //发起方公钥 TmpPublicKeyInitiator string `json:"tpk"` //发起方临时公钥 EncryptType string `json:"et"` //加密类型 PublicKeyResponder string `json:"pko"` //响应方公钥 TmpPublicKeyResponder string `json:"tpo"` //响应方临时公钥 SB string `json:"sb"` //响应方发送给发起方的校验值 SA string `json:"sa"` //发起方发送给响应方的校验值 S2 string `json:"s2"` //响应方协商密码计算的校验值 }
KeyAgreement 协商密码
type ServeMux ¶
type ServeMux struct {
// contains filtered or unexported fields
}
ServeMux 多路复用服务
func NewServeMux ¶
func (*ServeMux) AddRequest ¶
func (mux *ServeMux) AddRequest(peer Peer, nonce uint64, time int64, method string, reqFunc RequestFunc, respChan chan Response, sync bool) error
AddRequest 添加请求到队列 @param nonce 递增不可重复 @param method API方法名 @param reqFunc 异步请求的回调函数 @param respChan 同步请求的响应通道 @param sync 是否同步
func (*ServeMux) HandleFunc ¶
func (mux *ServeMux) HandleFunc(method string, handler HandlerFunc)
HandleFunc 路由处理器绑定 @param method API方法名 @param handler 处理方法入口
func (*ServeMux) RemoveRequest ¶
RemoveRequest 移除请求
func (*ServeMux) ResetRequestQueue ¶
ResetRequestQueue 重置请求队列
type SessionManager ¶
type SessionManager struct {
// contains filtered or unexported fields
}
SessionManager contains Provider and its configuration.
func NewSessionManager ¶
func NewSessionManager(provideName string, cf *session.ManagerConfig) (*SessionManager, error)
NewManager Create new Manager with provider name and json config string. provider name: 1. cookie 2. file 3. memory 4. redis 5. mysql json config: 1. is https default false 2. hashfunc default sha1 3. hashkey default beegosessionkey 4. maxage default is none
func (*SessionManager) Delete ¶
func (store *SessionManager) Delete(id string, key string) error
Delete
func (*SessionManager) GC ¶
func (store *SessionManager) GC()
GC Start session gc process. it can do gc in times after gc lifetime.
func (*SessionManager) Get ¶
func (store *SessionManager) Get(id string, key string) interface{}
Get 获取节点属性
func (*SessionManager) GetActiveSession ¶
func (store *SessionManager) GetActiveSession() int
GetActiveSession Get all active sessions count number.
func (*SessionManager) GetProvider ¶
func (store *SessionManager) GetProvider() session.Provider
GetProvider return current manager's provider
func (*SessionManager) GetSessionStore ¶
func (store *SessionManager) GetSessionStore(pid string) (sessions session.Store, err error)
GetSessionStore Get SessionStore by its id.
func (*SessionManager) GetString ¶
func (store *SessionManager) GetString(id string, key string) string
GetString
func (*SessionManager) PeerInfo ¶
func (store *SessionManager) PeerInfo(id string) PeerInfo
PeerInfo 节点信息
func (*SessionManager) Put ¶
func (store *SessionManager) Put(id string, key string, val interface{}) error
Put 设置节点属性
func (*SessionManager) SessionDestroy ¶
func (store *SessionManager) SessionDestroy(pid string)
SessionDestroy Destroy session by its id in http request cookie.
type WSClient ¶
type WSClient struct { ReadBufferSize int WriteBufferSize int // contains filtered or unexported fields }
WSClient 基于websocket的通信客户端
func Dial ¶
func Dial( pid, url string, handler PeerHandler, header map[string]string, ReadBufferSize, WriteBufferSize int) (*WSClient, error)
Dial connects a client to the given URL.
func NewWSClient ¶
func NewWSClient(pid string, conn *websocket.Conn, handler PeerHandler, auth Authorization, done func()) (*WSClient, error)
func NewWSClientWithHeader ¶
func NewWSClientWithHeader(header http.Header, cert Certificate, conn *websocket.Conn, handler PeerHandler, enableSignature bool, done func()) (*WSClient, error)
func (*WSClient) ConnectConfig ¶
func (c *WSClient) ConnectConfig() ConnectConfig