Best Testkube code snippet using client.GetServerInfo
auth_chain.go
Source:auth_chain.go
...184 }185 result = bytesx.ContactSlice(result, cleartext)186 a.LastServerHash = serverHash187 if a.RecvID == 1 {188 a.GetServerInfo().SetTCPMss(int(binaryx.LEBytesToUint16(result[:2])))189 result = result[2:]190 }191 a.RecvID = (a.RecvID + 1) & 0xFFFFFFFF192 a.RecvBuf = a.RecvBuf[length+4:]193 }194 return result, nil195}196func (a *AuthChainA) ServerPreEncrypt(buf []byte) (result []byte, err error) {197 if a.RawTrans {198 return buf, nil199 }200 result = []byte{}201 if a.PackID == 1 {202 var tcpMass int203 if a.GetServerInfo().GetTCPMss() < 1500 {204 tcpMass = a.GetServerInfo().GetTCPMss()205 } else {206 tcpMass = 1500207 }208 a.GetServerInfo().SetTCPMss(tcpMass)209 buf = bytesx.ContactSlice(binaryx.LEUInt16ToBytes(uint16(tcpMass)), buf)210 a.UnintLen = tcpMass - a.ClientOverhead211 }212 for len(buf) > a.UnintLen {213 packServerData, err := a.packServerData(buf[:a.UnintLen])214 if err != nil {215 return nil, err216 }217 result = bytesx.ContactSlice(result, packServerData)218 buf = buf[a.UnintLen:]219 }220 packServerData, err := a.packServerData(buf)221 if err != nil {222 return nil, err223 }224 result = bytesx.ContactSlice(result, packServerData)225 return result, nil226}227func (a *AuthChainA) ServerPostDecrypt(buf []byte) (result []byte, sendback bool, err error) {228 if a.RawTrans {229 return buf, false, nil230 }231 a.RecvBuf = bytesx.ContactSlice(a.RecvBuf, buf)232 result = []byte{}233 sendback = false234 var md5Data []byte235 if !a.HasRecvHeader {236 if len(a.RecvBuf) >= 12 || langx.IntIn(len(a.RecvBuf), []int{7, 8}) {237 recvLen := int(math.Min(float64(len(a.RecvBuf)), float64(12)))238 macKey := bytesx.ContactSlice(a.GetServerInfo().GetRecvIv(), a.GetServerInfo().GetKey())239 md5Data = hmacmd5(macKey, a.RecvBuf[:4])240 //logrus.WithFields(241 // logrus.Fields{242 // "md5Data": hex.EncodeToString(md5Data),243 // "key": hex.EncodeToString(a.GetServerInfo().GetKey()),244 // "randBytes": hex.EncodeToString(a.RecvBuf[:4]),245 // "recvIV": hex.EncodeToString(a.GetServerInfo().GetRecvIv()),246 // "recvLen": recvLen,247 // }).Debug("AuthChainA verify")248 if !bytes.Equal(md5Data[:recvLen-4], a.RecvBuf[4:recvLen]) {249 logrus.WithFields(logrus.Fields{250 "md5Data": hex.EncodeToString(md5Data[:recvLen-4]),251 "recvMd5Data": hex.EncodeToString(a.RecvBuf[4:recvLen]),252 }).Error("AuthChainA verify failed")253 result, sendback = a.NotMatchReturn(a.RecvBuf)254 err = nil255 return256 }257 }258 if len(a.RecvBuf) < 12+24 {259 return []byte{}, false, nil260 }261 a.LastClientHash = md5Data262 var uid int263 var uidPack []byte264 uid = int(binaryx.LEBytesToUInt32(a.RecvBuf[12:16]) ^ binaryx.LEBytesToUInt32(md5Data[8:12]))265 a.UserIDNum = uid266 uidPack = binaryx.LEUint32ToBytes(uint32(uid))267 if a.GetServerInfo().GetUsers()[string(uidPack)] != "" {268 a.UserID = uidPack269 a.UserKey = []byte(a.GetServerInfo().GetUsers()[string(uidPack)])270 a.GetServerInfo().UpdateUser(uidPack)271 } else {272 return []byte{}, false, errors.New(fmt.Sprintf("user %v not exist", uid))273 }274 md5Data = hmacmd5(a.UserKey, a.RecvBuf[12:12+20])275 if !bytes.Equal(md5Data[:4], a.RecvBuf[32:36]) {276 //logrus.WithFields(logrus.Fields{277 // "md5Data_4": hex.EncodeToString(md5Data[:4]),278 // "recvBuf_4": hex.EncodeToString(a.RecvBuf[32:36]),279 //}).Debug("auth_chain md5 equal error")280 logrus.Errorf("%s data uncorrect auth HMAC-MD5 from %s:%v, data %s",281 a.NoCompatibleMethod, a.GetServerInfo().282 GetClient().String(),283 a.GetServerInfo().GetPort(),284 hex.EncodeToString(a.RecvBuf))285 if len(a.RecvBuf) < 36 {286 return []byte{}, false, nil287 }288 result, sendback = a.NotMatchReturn(a.RecvBuf)289 return290 }291 a.LastServerHash = md5Data292 encryptor, err := ciphers.NewEncryptorWithIv("aes-128-cbc",293 string(bytesx.ContactSlice([]byte(base64.StdEncoding.EncodeToString(a.UserKey)), a.Salt)),294 bytes.Repeat([]byte{0x00}, 16))295 if err != nil {296 return nil, false, err297 }298 head, err := encryptor.Decrypt(bytesx.ContactSlice(bytes.Repeat([]byte{0x00}, 16), a.RecvBuf[16:32]))299 if err != nil {300 return nil, false, err301 }302 a.ClientOverhead = int(binaryx.LEBytesToUint16(head[12:16]))303 utcTime := binaryx.LEBytesToUInt32(head[:4])304 clientId := binaryx.LEBytesToUInt32(head[4:8])305 connectionId := binaryx.LEBytesToUInt32(head[8:12])306 timeDif := int(int64(utcTime) - time.Now().Unix()&0xFFFFFFFF)307 if timeDif < -a.MaxTimeDif || timeDif > a.MaxTimeDif {308 log.Info("%s: wrong timestamp, time_dif %v, data %s",309 a.NoCompatibleMethod,310 timeDif,311 hex.EncodeToString(head))312 result, sendback = a.NotMatchReturn(a.RecvBuf)313 return result, sendback, nil314 } else if core.GetApp().GetObfsProtocolService().Insert(a.UserID, int(clientId), int(connectionId)) {315 a.HasRecvHeader = true316 a.ClientID = int(clientId)317 a.ConnectionID = int(connectionId)318 } else {319 log.Info("%s: auth fail, data %s", a.NoCompatibleMethod, hex.EncodeToString(result))320 result, sendback = a.NotMatchReturn(a.RecvBuf)321 return result, sendback, nil322 }323 a.Encryptor, err = ciphers.NewEncryptor(324 "rc4",325 string(326 bytesx.ContactSlice(327 []byte(base64.StdEncoding.EncodeToString(a.UserKey)),328 []byte(base64.StdEncoding.EncodeToString(a.LastClientHash)),329 ),330 ),331 )332 a.RecvBuf = a.RecvBuf[36:]333 a.HasRecvHeader = true334 sendback = true335 }336 for len(a.RecvBuf) > 4 {337 macKey := bytesx.ContactSlice(a.UserKey, binaryx.LEUint32ToBytes(uint32(a.RecvID)))338 dataLen := binaryx.LEBytesToUint16(a.RecvBuf[:2]) ^ binaryx.LEBytesToUint16(a.LastClientHash[14:16])339 randLen := a.rndDataLen(int(dataLen), a.LastClientHash, a.RandomClient)340 length := int(dataLen) + randLen341 if length >= 4096 {342 a.RawTrans = true343 a.RecvBuf = []byte{}344 if a.RecvID == 1 {345 log.Info("%s: over size ", a.NoCompatibleMethod)346 return bytes.Repeat([]byte{byte('E')}, 2048), false, nil347 } else {348 return nil, false, errors.WithStack(errors.New("server_post_decrype data error"))349 }350 }351 if length+4 > len(a.RecvBuf) {352 break353 }354 clientHash := hmacmd5(macKey, a.RecvBuf[:length+2])355 if !bytes.Equal(clientHash[:2], a.RecvBuf[length+2:length+4]) {356 log.Info("%s checksum error, data %s", a.NoCompatibleMethod, hex.EncodeToString(a.RecvBuf[:length]))357 a.RawTrans = true358 a.RecvBuf = []byte{}359 if a.RecvID == 1 {360 return bytes.Repeat([]byte{byte('E')}, 2048), false, nil361 } else {362 return nil, false, errors.WithStack(errors.New("server_post_decrype data uncorrect checksum"))363 }364 }365 a.RecvID = (a.RecvID + 1) & 0xFFFFFFFF366 pos := 2367 if dataLen > 0 && randLen > 0 {368 pos = 2 + a.rndStartPos(randLen, a.RandomClient)369 }370 clearText, err := a.Encryptor.Decrypt(a.RecvBuf[pos : int(dataLen)+pos])371 if err != nil {372 return nil, false, err373 }374 result = bytesx.ContactSlice(result, clearText)375 a.LastClientHash = clientHash376 a.RecvBuf = a.RecvBuf[length+4:]377 if dataLen == 0 {378 sendback = true379 }380 }381 if len(result) > 0 {382 core.GetApp().GetObfsProtocolService().Update(a.UserID, a.ClientID, a.ConnectionID)383 }384 return result, sendback, nil385}386func (a *AuthChainA) ClientUDPPreEncrypt(buf []byte) ([]byte, error) {387 if a.UserKey == nil {388 param := a.GetServerInfo().GetProtocolParam()389 if strings.Contains(param, ":") {390 items := strings.Split(param, ":")391 if len(items) > 1 {392 md5Data := []byte(items[1])393 a.UserKey = md5Data[:]394 uidInt, err := strconv.Atoi(items[0])395 if err != nil {396 return nil, err397 }398 uidPack := binaryx.LEUint32ToBytes(uint32((uidInt)))399 a.UserID = uidPack400 }401 }402 if a.UserKey == nil {403 a.UserID = randomx.RandomBytes(4)404 a.UserKey = a.GetServerInfo().GetKey()405 }406 }407 authData := randomx.RandomBytes(3)408 macKey := a.GetServerInfo().GetKey()409 md5Data := hmacmd5(macKey, authData)410 uid := binaryx.LEBytesToUInt32(a.UserID) ^ binaryx.LEBytesToUInt32(md5Data[0:4])411 uidPack := binaryx.LEUint32ToBytes(uid)412 randLen := a.udpRndDataLen(md5Data, a.RandomClient)413 rc4Key := bytesx.ContactSlice(414 []byte(base64.StdEncoding.EncodeToString(a.UserKey)),415 []byte(base64.StdEncoding.EncodeToString(md5Data)),416 )417 encryptor, err := ciphers.NewEncryptor("rc4", string(rc4Key))418 if err != nil {419 return nil, err420 }421 result, err := encryptor.Encrypt(buf)422 if err != nil {423 return nil, err424 }425 result = bytesx.ContactSlice(result, randomx.RandomBytes(randLen), authData, uidPack)426 return bytesx.ContactSlice(result, hmacmd5(a.UserKey, result)[:1]), nil427}428func (a *AuthChainA) ClientUDPPostDecrypt(buf []byte) ([]byte, error) {429 if len(buf) < 8 {430 return []byte{}, nil431 }432 if bytes.Equal(hmacmd5(a.UserKey, buf[:len(buf)])[:1], buf[len(buf)-1:]) {433 return []byte{}, nil434 }435 macKey := a.GetServerInfo().GetKey()436 md5Data := hmacmd5(macKey, buf[len(buf)-8:len(buf)-1])437 randLen := a.udpRndDataLen(md5Data, a.RandomServer)438 rc4Key := bytesx.ContactSlice(439 []byte(base64.StdEncoding.EncodeToString(a.UserKey)),440 []byte(base64.StdEncoding.EncodeToString(md5Data)),441 )442 encryptor, err := ciphers.NewEncryptor("rc4", string(rc4Key))443 if err != nil {444 return nil, err445 }446 return encryptor.Decrypt(buf[:len(buf)-8-randLen])447}448func (a *AuthChainA) ServerUDPPreEncrypt(buf, uid []byte) ([]byte, error) {449 var userKey []byte450 if a.GetServerInfo().GetUsers()[string(uid)] != "" {451 userKey = []byte(a.GetServerInfo().GetUsers()[string(uid)])452 } else {453 uid = nil454 if len(a.GetServerInfo().GetUsers()) == 0 {455 userKey = a.GetServerInfo().GetKey()456 } else {457 userKey = a.GetServerInfo().GetRecvIv()458 }459 }460 authData := randomx.RandomBytes(7)461 macKey := a.GetServerInfo().GetKey()462 md5Data := hmacmd5(macKey, authData)463 randLen := a.udpRndDataLen(md5Data, a.RandomServer)464 rc4Key := bytesx.ContactSlice(465 []byte(base64.StdEncoding.EncodeToString(userKey)),466 []byte(base64.StdEncoding.EncodeToString(md5Data)),467 )468 encryptor, err := ciphers.NewEncryptor("rc4", string(rc4Key))469 if err != nil {470 return nil, err471 }472 result, err := encryptor.Encrypt(buf)473 if err != nil {474 return nil, err475 }476 result = bytesx.ContactSlice(result, randomx.RandomBytes(randLen), authData)477 result = bytesx.ContactSlice(result, hmacmd5(userKey, result)[:1])478 return result, nil479}480func (a *AuthChainA) ServerUDPPostDecrypt(buf []byte) ([]byte, string, error) {481 macKey := a.GetServerInfo().GetKey()482 md5Data := hmacmd5(macKey, buf[len(buf)-8:len(buf)-5])483 uid := binaryx.LEBytesToUInt32(buf[len(buf)-5:len(buf)-1]) ^ binaryx.LEBytesToUInt32(md5Data[:4])484 uidPack := binaryx.LEUint32ToBytes(uid)485 var userKey []byte486 if a.GetServerInfo().GetUsers()[string(uidPack)] != "" {487 userKey = []byte(a.GetServerInfo().GetUsers()[string(uidPack)])488 } else {489 userKey = nil490 if len(a.GetServerInfo().GetUsers()) == 0 {491 userKey = a.GetServerInfo().GetKey()492 } else {493 userKey = a.GetServerInfo().GetRecvIv()494 }495 }496 if bytes.Equal(hmacmd5(userKey, buf[:len(buf)])[:1], buf[len(buf)-1:]) {497 return []byte{}, "", nil498 }499 randLen := a.udpRndDataLen(md5Data, a.RandomServer)500 rc4Key := bytesx.ContactSlice(501 []byte(base64.StdEncoding.EncodeToString(userKey)),502 []byte(base64.StdEncoding.EncodeToString(md5Data)),503 )504 encryptor, err := ciphers.NewEncryptor("rc4", string(rc4Key))505 if err != nil {506 return nil, "", err507 }508 if len(buf)-8-randLen < 0 {509 return nil, "", errors.New("auth_chain_a buf is too short")510 }511 result, err := encryptor.Decrypt(buf[:len(buf)-8-randLen])512 if err != nil {513 return nil, "", err514 }515 return result, string(uidPack), nil516}517func (a *AuthChainA) Dispose() {518 core.GetApp().GetObfsProtocolService().Remove(string(a.UserID), a.ClientID)519}520func (a *AuthChainA) trapezoidRandomFloat(d float64) float64 {521 if d == 0 {522 return randomx.Float64()523 }524 s := randomx.Float64()525 tmp := 1 - d526 return (math.Sqrt(tmp*tmp+4*d*s) - tmp) / (2 * d)527}528func (a *AuthChainA) trapezoidRandomInt(maxVal, d float64) int {529 v := a.trapezoidRandomFloat(d)530 return int(v * maxVal)531}532func (a *AuthChainA) rndDataLen(bufSize int, lastHash []byte, random *XorShift128Plus) int {533 if bufSize > 1440 {534 return 0535 }536 random.InitFromBinLen(lastHash, bufSize)537 if bufSize > 1300 {538 return int(random.Next() % 31)539 }540 if bufSize > 900 {541 return int(random.Next() % 127)542 }543 if bufSize > 400 {544 return int(random.Next() % 521)545 }546 return int(random.Next() % 1021)547}548func (a *AuthChainA) udpRndDataLen(lastHash []byte, random *XorShift128Plus) int {549 random.InitFromBin(lastHash)550 return int(random.Next() % 127)551}552func (a *AuthChainA) rndStartPos(randLen int, random *XorShift128Plus) int {553 if randLen > 0 {554 return int(random.Next() % 8589934609 % uint64(randLen))555 }556 return 0557}558func (a *AuthChainA) rndData(bufSize int, buf []byte, lastHashe []byte, random *XorShift128Plus) []byte {559 randLen := a.rndDataLen(bufSize, lastHashe, random)560 rndDataBuf := randomx.RandomBytes(randLen)561 if bufSize == 0 {562 return rndDataBuf563 } else {564 if randLen > 0 {565 startPos := a.rndStartPos(randLen, random)566 return conbineToBytes(rndDataBuf[:startPos], buf, rndDataBuf[startPos:])567 } else {568 return buf569 }570 }571}572func (a *AuthChainA) packClientData(buf []byte) ([]byte, error) {573 buf, err := a.Encryptor.Encrypt(buf)574 if err != nil {575 return nil, err576 }577 data := a.rndData(len(buf), buf, a.LastClientHash, a.RandomClient)578 macKey := bytesx.ContactSlice(a.UserKey, binaryx.BEUInt32ToBytes(uint32((a.PackID))))579 length := len(buf) ^ int(binaryx.LEBytesToUint16(a.LastClientHash[14:]))580 data = bytesx.ContactSlice(binaryx.LEUInt16ToBytes(uint16(length)), data)581 a.LastClientHash = hmacmd5(macKey, data)582 data = bytesx.ContactSlice(data, a.LastClientHash[:2])583 a.PackID = (a.PackID + 1) & 0xFFFFFFFF584 return data, nil585}586func (a *AuthChainA) packServerData(buf []byte) ([]byte, error) {587 buf, err := a.Encryptor.Encrypt(buf)588 if err != nil {589 return nil, err590 }591 data := a.rndData(len(buf), buf, a.LastServerHash, a.RandomServer)592 macKey := bytesx.ContactSlice(a.UserKey, binaryx.LEUint32ToBytes(uint32(a.PackID)))593 length := len(buf) ^ int(binaryx.LEBytesToUint16(a.LastServerHash[14:]))594 data = bytesx.ContactSlice(binaryx.LEUInt16ToBytes(uint16(length)), data)595 a.LastServerHash = hmacmd5(macKey, data)596 data = bytesx.ContactSlice(data, a.LastServerHash[:2])597 a.PackID = (a.PackID + 1) & 0xFFFFFFFF598 return data, nil599}600func (a *AuthChainA) packAuthData(authData, buf []byte) (result []byte, err error) {601 data := authData602 data = bytesx.ContactSlice(data, binaryx.LEUInt16ToBytes(uint16(a.GetServerInfo().GetOverhead())), binaryx.LEUInt16ToBytes(0))603 macKey := bytesx.ContactSlice(a.GetServerInfo().GetIv(), a.GetServerInfo().GetKey())604 checkHead := randomx.RandomBytes(4)605 a.LastClientHash = hmacmd5(macKey, checkHead)606 checkHead = bytesx.ContactSlice(checkHead, a.LastClientHash[:8])607 param := a.GetServerInfo().GetProtocolParam()608 var uidPack []byte609 if strings.Contains(param, ":") {610 items := strings.Split(param, ":")611 if len(items) > 1 {612 a.UserKey = []byte(items[1])613 uidInt, err := strconv.Atoi(items[0])614 if err != nil {615 return nil, err616 }617 uidPack = binaryx.LEUint32ToBytes(uint32((uidInt)))618 } else {619 uidPack = randomx.RandomBytes(4)620 }621 } else {622 uidPack = randomx.RandomBytes(4)623 }624 if a.UserKey == nil {625 a.UserKey = a.GetServerInfo().GetKey()626 }627 encryptor, err := ciphers.NewEncryptorWithIv("aes-128-cbc",628 string(bytesx.ContactSlice([]byte(base64.StdEncoding.EncodeToString(a.UserKey)), a.Salt)),629 bytes.Repeat([]byte{0x00}, 16))630 if err != nil {631 return nil, err632 }633 uid := binaryx.LEBytesToUInt32([]byte{uidPack[0], uidPack[1], 0x00, 0x00}) ^ binaryx.LEBytesToUInt32(a.LastClientHash[8:12])634 uidPack = binaryx.LEUint32ToBytes(uint32(uid))635 dataCipherText, err := encryptor.Encrypt(data)636 if err != nil {637 return nil, err638 }639 data = bytesx.ContactSlice(uidPack, dataCipherText[16:])...
node2client.go
Source:node2client.go
...37 client.conn = nil38 client.client = nil39 client.lastTaskNums = 140}41// GetServerInfo - getServerInfo42func (client *Node2Client) GetServerInfo(ctx context.Context, logger *zap.Logger) (*tradingpb.ReplyServerInfo, error) {43 if client.conn == nil || client.client == nil {44 conn, err := grpc.Dial(client.servAddr, grpc.WithInsecure())45 if err != nil {46 if logger != nil {47 logger.Error("Node2Client.GetServerInfo:grpc.Dial",48 zap.String("server address", client.servAddr),49 zap.Error(err))50 } else {51 tradingdb2utils.Error("Node2Client.GetServerInfo:grpc.Dial",52 zap.String("server address", client.servAddr),53 zap.Error(err))54 }55 return nil, err56 }57 client.conn = conn58 client.client = tradingpb.NewTradingNode2Client(conn)59 }60 req := &tradingpb.RequestServerInfo{61 BasicRequest: &tradingpb.BasicRequestData{62 Token: client.token,63 },64 }65 reply, err := client.client.GetServerInfo(ctx, req)66 if err != nil {67 if logger != nil {68 logger.Error("Node2Client.GetServerInfo:Client.GetServerInfo",69 zap.Error(err))70 } else {71 tradingdb2utils.Error("Node2Client.GetServerInfo:Client.GetServerInfo",72 zap.Error(err))73 }74 // if error, reset75 client.reset()76 return nil, err77 }78 client.lastTaskNums = int(reply.NodeInfo.MaxTasks - reply.NodeInfo.CurTasks)79 tradingdb2utils.Debug("Node2Client.GetServerInfo",80 tradingdb2utils.JSON("reply", reply))81 return reply, nil82}83// hold - å¾å°ä¸ä¸ªç©ºé²çclientåï¼åºè¯¥é©¬ä¸hold84func (client *Node2Client) hold() error {85 if client.lastTaskNums <= 0 {86 tradingdb2utils.Error("Node2Client.hold",87 zap.Error(ErrNodeNotFree))88 return ErrNodeNotFree89 }90 client.lastTaskNums--91 client.lastTs = time.Now().Unix()92 return nil93}94// freeHold - hold以åï¼åç°æ²¡æä»»å¡ï¼åºè¯¥freeHold95func (client *Node2Client) freeHold() {96 client.lastTaskNums++97}98// calcPNL - calcPNL99func (client *Node2Client) calcPNL(ctx context.Context, params *tradingpb.SimTradingParams, logger *zap.Logger) (*tradingpb.ReplyCalcPNL, error) {100 // if client.lastTaskNums <= 0 {101 // if time.Now().Unix()-client.lastTs < TradingNode2RequestOffTime {102 // tradingdb2utils.Error("Node2Client.calcPNL",103 // zap.Error(ErrNodeNotFree))104 // return nil, ErrNodeNotFree105 // }106 // client.GetServerInfo(ctx, logger)107 // if client.lastTaskNums <= 0 {108 // return nil, ErrNodeNotFree109 // }110 // }111 // client.lastTaskNums--112 // client.lastTs = time.Now().Unix()113 if client.conn == nil || client.client == nil {114 conn, err := grpc.Dial(client.servAddr, grpc.WithInsecure())115 if err != nil {116 if logger != nil {117 logger.Error("Client.calcPNL:grpc.Dial",118 zap.String("server address", client.servAddr),119 zap.Error(err))120 } else {121 tradingdb2utils.Error("Client.calcPNL:grpc.Dial",122 zap.String("server address", client.servAddr),123 zap.Error(err))124 }125 client.GetServerInfo(ctx, logger)126 return nil, err127 }128 client.conn = conn129 client.client = tradingpb.NewTradingNode2Client(conn)130 }131 req := &tradingpb.RequestCalcPNL{132 BasicRequest: &tradingpb.BasicRequestData{133 Token: client.token,134 },135 Params: params,136 }137 reply, err := client.client.CalcPNL(ctx, req)138 if err != nil {139 if logger != nil {140 logger.Error("Client.calcPNL:Client.CalcPNL",141 zap.Error(err),142 zap.String("servAddr", client.servAddr))143 } else {144 tradingdb2utils.Error("Client.calcPNL:Client.CalcPNL",145 zap.Error(err),146 zap.String("servAddr", client.servAddr))147 }148 // if error, reset149 client.reset()150 client.GetServerInfo(ctx, logger)151 return nil, err152 }153 if reply.NodeInfo != nil {154 client.lastTaskNums = int(reply.NodeInfo.MaxTasks - reply.NodeInfo.CurTasks)155 tradingdb2utils.Debug("Node2Client.CalcPNL:NodeInfo",156 tradingdb2utils.JSON("reply.NodeInfo", reply.NodeInfo))157 } else {158 client.lastTaskNums++159 tradingdb2utils.Debug("Node2Client.CalcPNL:non-NodeInfo",160 tradingdb2utils.JSON("lastTaskNums", client.lastTaskNums))161 }162 return reply, nil163}...
GetServerInfo
Using AI Code Generation
1import (2type Client struct {3}4func (c *Client) GetServerInfo() (string, error) {5 err := c.Client.Call("Server.GetServerInfo", "", &reply)6 if err != nil {7 log.Fatal("Server error: ", err)8 }9}10func main() {11 client, err := rpc.DialHTTP("tcp", "
GetServerInfo
Using AI Code Generation
1import (2const (3func main() {4 creds, err := credentials.NewClientTLSFromFile(testdata.Path("ca.pem"), "x.test.youtube.com")5 if err != nil {6 log.Fatalf("could not load tls cert: %s", err)7 }8 conn, err := grpc.Dial(address, grpc.WithTransportCredentials(creds))9 if err != nil {10 log.Fatalf("did not connect: %v", err)11 }12 defer conn.Close()13 c := pb.NewGreeterClient(conn)14 if len(os.Args) > 1 {15 }16 r, err := c.GetServerInfo(context.Background(), &pb.HelloRequest{Name: name})17 if err != nil {18 log.Fatalf("could not greet: %v", err)19 }20 log.Printf("Greeting: %s", r.Message)21}22import (23const (24func main() {25 creds, err := credentials.NewClientTLSFromFile(testdata.Path("ca.pem"), "x.test.youtube.com")26 if err != nil {27 log.Fatalf("could not load tls cert: %s", err)28 }29 conn, err := grpc.Dial(address, grpc.WithTransportCredentials(creds))30 if err != nil {31 log.Fatalf("did not connect: %v", err)32 }33 defer conn.Close()34 c := pb.NewGreeterClient(conn)
GetServerInfo
Using AI Code Generation
1import (2func main() {3 str, err := req.String()4 if err != nil {5 fmt.Println(err)6 }7 fmt.Println(str)8}9{10 "data": {
GetServerInfo
Using AI Code Generation
1import (2const (3func main() {4 conn, err := grpc.Dial(address, grpc.WithInsecure())5 if err != nil {6 log.Fatalf("did not connect: %v", err)7 }8 defer conn.Close()9 c := pb.NewClientServiceClient(conn)10 r, err := c.GetServerInfo(context.Background(), &pb.ClientRequest{Name: name})11 if err != nil {12 log.Fatalf("could not greet: %v", err)13 }14 log.Printf("Greeting: %s", r.GetMessage())15}16import (17const (18func main() {19 conn, err := grpc.Dial(address, grpc.WithInsecure())20 if err != nil {21 log.Fatalf("did not connect: %v", err)22 }23 defer conn.Close()24 c := pb.NewClientServiceClient(conn)25 r, err := c.GetServerInfoStream(context.Background(), &pb.ClientRequest{Name: name})26 if err != nil {27 log.Fatalf("could not greet: %v", err)28 }29 for {30 res, err := r.Recv()31 if err == io.EOF {32 }33 if err != nil {34 log.Fatalf("could not greet: %v", err)35 }36 log.Printf("Greeting: %s", res.GetMessage())37 }38}39import (40const (41func main() {42 conn, err := grpc.Dial(address, grpc.WithInsecure())43 if err != nil {44 log.Fatalf("
GetServerInfo
Using AI Code Generation
1import (2func main() {3 c := client.NewClient()4 info, err := c.GetServerInfo()5 if err != nil {6 fmt.Printf("error: %v7 }8 fmt.Printf("info: %+v9}10import (11func main() {12 c := client.NewClient()13 info, err := c.GetServerInfo()14 if err != nil {15 fmt.Printf("error: %v16 }17 fmt.Printf("info: %+v18}19import (20func main() {21 c := client.NewClient()22 info, err := c.GetServerInfo()23 if err != nil {24 fmt.Printf("error: %v25 }26 fmt.Printf("info: %+v27}28import (29func main() {30 c := client.NewClient()31 info, err := c.GetServerInfo()32 if err != nil {33 fmt.Printf("error: %v34 }35 fmt.Printf("info: %+v36}37import (38func main() {39 c := client.NewClient()40 info, err := c.GetServerInfo()41 if err != nil {42 fmt.Printf("error: %v43 }44 fmt.Printf("info: %+v45}
GetServerInfo
Using AI Code Generation
1import (2func main() {3 c.GetServerInfo()4}5import (6func GetServerInfo() {7 fmt.Println("GetServerInfo")8}9import "client"10import "client/client"11import (12func main() {13 c.GetServerInfo()14}15import "client"16import "client/client"17import (18func main() {19 c.GetServerInfo()20}21import "client"22import "client/client"23import (24func main() {25 c.GetServerInfo()26}
GetServerInfo
Using AI Code Generation
1import (2const (3func main() {4 conn, err := grpc.Dial(address, grpc.WithInsecure())5 if err != nil {6 log.Fatalf("did not connect: %v", err)7 }8 defer conn.Close()9 c := pb.NewHelloServiceClient(conn)10 r, err := c.GetServerInfo(context.Background(), &pb.HelloRequest{Name: name})11 if err != nil {12 log.Fatalf("could not greet: %v", err)13 }14 log.Printf("Greeting: %s", r.GetMessage())15}16import (17const (18func main() {19 conn, err := grpc.Dial(address, grpc.WithInsecure())20 if err != nil {21 log.Fatalf("did not connect: %v", err)22 }23 defer conn.Close()24 c := pb.NewHelloServiceClient(conn)25 r, err := c.GetServerInfo(context.Background(), &pb.HelloRequest{Name: name})26 if err != nil {27 log.Fatalf("could not greet: %v", err)28 }29 log.Printf("Greeting: %s", r.GetMessage())30}31import (32const (33func main() {34 conn, err := grpc.Dial(address, grpc.WithInsecure())35 if err != nil {36 log.Fatalf("did not connect:
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!