本文整理匯總了Golang中github.com/gsrpc/gorpc.Context.Name方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.Name方法的具體用法?Golang Context.Name怎麽用?Golang Context.Name使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/gsrpc/gorpc.Context
的用法示例。
在下文中一共展示了Context.Name方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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
}