本文整理汇总了Golang中github.com/gsrpc/gorpc.Context类的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Context类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Active
func (handler *_TunnelClient) Active(context gorpc.Context) error {
handler.agents = make(map[string]*_Agent)
handler.system.addTunnel(handler.name, handler, context.Pipeline())
// send TunnelWhoAmI
whoAmI := gorpc.NewTunnelWhoAmI()
whoAmI.Services = handler.system.system.AgentServices()
var buff bytes.Buffer
gorpc.WriteTunnelWhoAmI(&buff, whoAmI)
message := gorpc.NewMessage()
message.Code = gorpc.CodeTunnelWhoAmI
message.Content = buff.Bytes()
context.Send(message)
return nil
}
开发者ID:gsdocker,项目名称:gsproxy,代码行数:26,代码来源:tunnel.go
示例2: timeoutLoop
func (handler *_HeartbeatHandler) timeoutLoop(context gorpc.Context, exitflag chan bool) {
wheel := context.Pipeline().TimeWheel()
ticker := wheel.NewTicker(handler.timeout)
defer ticker.Stop()
for {
select {
case <-ticker.C:
if time.Now().Sub(handler.timestamp) > handler.timeout*2 {
handler.context.Close()
handler.W("heartbeat timeout(%s), close current pipeline(%s)", handler.timeout*2, handler.context.Pipeline())
return
}
message := gorpc.NewMessage()
message.Code = gorpc.CodeHeartbeat
handler.context.Send(message)
handler.V("%s send heartbeat message", handler.context.Pipeline())
case <-exitflag:
handler.V("exit heartbeat loop .....................")
return
}
}
}
开发者ID:gsrpc,项目名称:gorpc,代码行数:33,代码来源:heartbeat.go
示例3: Inactive
func (handler *_TunnelClient) Inactive(context gorpc.Context) {
for _, agent := range handler.agents {
handler.system.system.UnbindAgent(agent)
}
handler.system.removeTunnel(handler.name, handler, context.Pipeline())
}
开发者ID:gsdocker,项目名称:gsproxy,代码行数:7,代码来源:tunnel.go
示例4: Active
func (handler *_CryptoClient) Active(context gorpc.Context) error {
// create whoAmI message
message := gorpc.NewMessage()
message.Code = gorpc.CodeWhoAmI
whoAmI := gorpc.NewWhoAmI()
whoAmI.ID = handler.device
whoAmI.Context = []byte(handler.dhKey.Exchange().String())
var buff bytes.Buffer
err := gorpc.WriteWhoAmI(&buff, whoAmI)
if err != nil {
context.Close()
return err
}
message.Content = buff.Bytes()
handler.V("send whoAmI handshake")
context.Send(message)
return gorpc.ErrSkip
}
开发者ID:gsrpc,项目名称:gorpc,代码行数:31,代码来源:dh.go
示例5: Active
func (handler *_TransProxyHandler) Active(context gorpc.Context) error {
dh, _ := context.Pipeline().Handler(dhHandler)
handler.device = dh.(gorpcHandler.CryptoServer).GetDevice()
return nil
}
开发者ID:gsdocker,项目名称:gsproxy,代码行数:8,代码来源:handlers.go
示例6: Active
func (client *_Client) Active(context gorpc.Context) error {
dh, _ := context.Pipeline().Handler(dhHandler)
device := dh.(handler.CryptoServer).GetDevice()
client.pipeline = context.Pipeline()
client.device = device
client.context.addClient(client)
return nil
}
开发者ID:gsdocker,项目名称:gsproxy,代码行数:14,代码来源:client.go
示例7: MessageReceived
func (handler *_TunnelServerHandler) MessageReceived(context gorpc.Context, message *gorpc.Message) (*gorpc.Message, error) {
if message.Code == gorpc.CodeTunnelWhoAmI {
handler.I("tunnel handshake ......")
whoAmI, err := gorpc.ReadTunnelWhoAmI(bytes.NewBuffer(message.Content))
if err != nil {
return nil, err
}
handler.proxy.proxy.BindServices(handler.proxy, context.Pipeline(), whoAmI.Services)
context.FireActive()
return nil, nil
}
if message.Code != gorpc.CodeTunnel {
return message, nil
}
handler.V("backward tunnel message")
tunnel, err := gorpc.ReadTunnel(bytes.NewBuffer(message.Content))
if err != nil {
handler.E("backward tunnel(%s) message -- failed\n%s", tunnel.ID, err)
return nil, err
}
if device, ok := handler.proxy.client(tunnel.ID); ok {
tunnel.Message.Agent = handler.id
err := device.SendMessage(tunnel.Message)
if err == nil {
handler.V("backward tunnel message -- success")
return nil, nil
}
return nil, err
}
handler.E("backward tunnel(%s) message -- failed,device not found", tunnel.ID)
return nil, nil
}
开发者ID:gsdocker,项目名称:gsproxy,代码行数:50,代码来源:handlers.go
示例8: MessageReceived
func (handler *_HeartbeatHandler) MessageReceived(context gorpc.Context, message *gorpc.Message) (*gorpc.Message, error) {
if message.Code == gorpc.CodeHeartbeat {
handler.V("%s recv heartbeat message", context.Pipeline())
if handler.timeout != 0 {
handler.timestamp = time.Now()
}
return nil, nil
}
return message, nil
}
开发者ID:gsrpc,项目名称:gorpc,代码行数:15,代码来源:heartbeat.go
示例9: newAgent
func newAgent(ctx gorpc.Context, handler *_TunnelClient, device *gorpc.Device) (*_Agent, error) {
context := &_Agent{
handler: handler,
id: device,
}
context.Sink = gorpc.NewSink(device.String(), context, ctx.Pipeline().TimeWheel(), handler.timeout)
var err error
err = handler.system.system.BindAgent(context)
if err != nil {
return nil, err
}
return context, nil
}
开发者ID:gsdocker,项目名称:gsproxy,代码行数:18,代码来源:tunnel.go
示例10: Inactive
func (handler *_StateHandler) Inactive(context gorpc.Context) {
handler.f(context.Pipeline(), gorpc.StateDisconnect)
}
开发者ID:gsrpc,项目名称:gorpc,代码行数:3,代码来源:state.go
示例11: Unregister
func (handler *_StateHandler) Unregister(context gorpc.Context) {
handler.f(context.Pipeline(), gorpc.StateClosed)
}
开发者ID:gsrpc,项目名称:gorpc,代码行数:3,代码来源:state.go
示例12: Active
func (handler *_StateHandler) Active(context gorpc.Context) error {
handler.f(context.Pipeline(), gorpc.StateConnected)
return nil
}
开发者ID:gsrpc,项目名称:gorpc,代码行数:4,代码来源:state.go
示例13: MessageReceived
func (handler *_CryptoClient) MessageReceived(context gorpc.Context, message *gorpc.Message) (*gorpc.Message, error) {
if message.Code == gorpc.CodeHeartbeat {
return message, nil
}
if handler.block == nil {
handler.V("expect handshake accept")
if message.Code != gorpc.CodeAccept {
handler.E("unexpect message(%s)", message.Code)
context.Close()
return nil, gserrors.Newf(gorpc.ErrRPC, "expect handshake(Accept) but got(%s)", message.Code)
}
handler.V("parse handshake accept")
val, ok := new(big.Int).SetString(string(message.Content), 0)
if !ok {
context.Close()
return nil, gserrors.Newf(gorpc.ErrRPC, "parse Accept#Content as big.Int error")
}
key := make([]byte, des.BlockSize)
keyval := handler.dhKey.Gen(val).Uint64()
binary.BigEndian.PutUint64(key[:8], keyval)
handler.V("shared key \n\t%d\n\t%v ", keyval, key)
block, err := des.NewCipher(key)
if err != nil {
context.Close()
return nil, gserrors.Newf(err, "create new des Cipher error")
}
handler.block = block
handler.V("%s handshake -- success", context.Name())
context.FireActive()
for _, message := range handler.cached {
message, _ = handler.MessageSending(context, message)
context.Send(message)
}
handler.cached = nil
return nil, nil
}
if message.Code == gorpc.CodeHeartbeat {
return message, nil
}
blocksize := handler.block.BlockSize()
if len(message.Content)%blocksize != 0 {
context.Close()
return nil, gserrors.Newf(gorpc.ErrRPC, "%s invalid encrypt data", context)
}
blocks := len(message.Content) / blocksize
for i := 0; i < blocks; i++ {
offset := i * blocksize
v := message.Content[offset : offset+blocksize]
handler.block.Decrypt(v, v)
}
message.Content = PKCS5UnPadding(message.Content)
return message, nil
}
开发者ID:gsrpc,项目名称:gorpc,代码行数:82,代码来源:dh.go
示例14: Inactive
func (handler *_TunnelServerHandler) Inactive(context gorpc.Context) {
go handler.proxy.proxy.UnbindServices(handler.proxy, context.Pipeline())
}
开发者ID:gsdocker,项目名称:gsproxy,代码行数:3,代码来源:handlers.go
注:本文中的github.com/gsrpc/gorpc.Context类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论