本文整理汇总了Golang中github.com/gsrpc/gorpc.Message类的典型用法代码示例。如果您正苦于以下问题:Golang Message类的具体用法?Golang Message怎么用?Golang Message使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Message类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: forward
func (handler *_TransProxyHandler) forward(server Server, message *gorpc.Message) error {
handler.V("forward tunnel(%s) message", handler.device)
tunnel := gorpc.NewTunnel()
tunnel.ID = handler.device
tunnel.Message = message
var buff bytes.Buffer
err := gorpc.WriteTunnel(&buff, tunnel)
if err != nil {
return err
}
message.Code = gorpc.CodeTunnel
message.Content = buff.Bytes()
err = server.SendMessage(message)
if err == nil {
handler.V("forward tunnel(%s) message(%p) -- success", handler.device, message)
} else {
handler.E("forward tunnel(%s) message -- failed\n%s", handler.device, err)
}
return err
}
开发者ID:gsdocker,项目名称:gsproxy,代码行数:31,代码来源:handlers.go
示例2: MessageSending
func (handler *_CryptoClient) MessageSending(context gorpc.Context, message *gorpc.Message) (*gorpc.Message, error) {
if handler.block != nil {
blocksize := handler.block.BlockSize()
content := PKCS5Padding(message.Content, blocksize)
blocks := len(content) / blocksize
for i := 0; i < blocks; i++ {
offset := i * blocksize
v := content[offset : offset+blocksize]
handler.block.Encrypt(v, v)
}
message.Content = content
handler.V("encrypt message content[blocksize :%d, blocks :%d]", blocksize, blocks)
return message, nil
}
handler.cached = append(handler.cached, message)
return nil, nil
}
开发者ID:gsrpc,项目名称:gorpc,代码行数:27,代码来源:dh.go
示例3: SendMessage
func (handler *_TunnelClient) SendMessage(device *gorpc.Device, message *gorpc.Message) error {
tunnel := gorpc.NewTunnel()
tunnel.ID = device
tunnel.Message = message
var buff bytes.Buffer
err := gorpc.WriteTunnel(&buff, tunnel)
if err != nil {
return err
}
message.Code = gorpc.CodeTunnel
message.Content = buff.Bytes()
handler.context.Send(message)
return nil
}
开发者ID:gsdocker,项目名称:gsproxy,代码行数:23,代码来源:tunnel.go
示例4: 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
示例5: MessageReceived
func (handler *_TransProxyHandler) MessageReceived(context gorpc.Context, message *gorpc.Message) (*gorpc.Message, error) {
if message.Code == gorpc.CodeResponse {
if server, ok := handler.tunnel(message.Agent); ok {
err := handler.forward(server, message)
if err != nil {
context.Close()
}
return nil, err
}
return message, nil
}
if message.Code != gorpc.CodeRequest {
return message, nil
}
request, err := gorpc.ReadRequest(bytes.NewBuffer(message.Content))
if err != nil {
handler.E("[%s] unmarshal request error\n%s", handler.proxy.name, err)
return nil, err
}
service := request.Service
if transproxy, ok := handler.transproxy(service); ok {
handler.V("forward tunnel(%s) message", handler.device)
tunnel := gorpc.NewTunnel()
tunnel.ID = handler.device
tunnel.Message = message
var buff bytes.Buffer
err := gorpc.WriteTunnel(&buff, tunnel)
if err != nil {
return nil, err
}
message.Code = gorpc.CodeTunnel
message.Content = buff.Bytes()
err = transproxy.SendMessage(message)
if err != nil {
context.Close()
handler.V("forward tunnel(%s) message(%p) -- failed\n%s", handler.device, message, err)
return nil, err
}
handler.V("forward tunnel(%s) message(%p) -- success", handler.device, message)
return nil, err
}
return message, nil
}
开发者ID:gsdocker,项目名称:gsproxy,代码行数:70,代码来源:handlers.go
注:本文中的github.com/gsrpc/gorpc.Message类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论