Пример #1
0
// usageString returns a description of the amount of space taken up by a body
// with the given contents and a bool indicating overflow.
func (draft *Draft) usageString() (string, bool) {
	var replyToId *uint64
	if draft.inReplyTo != 0 {
		replyToId = proto.Uint64(1)
	}
	var dhPub [32]byte

	msg := &pond.Message{
		Id:               proto.Uint64(0),
		Time:             proto.Int64(1 << 62),
		Body:             []byte(draft.body),
		BodyEncoding:     pond.Message_RAW.Enum(),
		InReplyTo:        replyToId,
		MyNextDh:         dhPub[:],
		Files:            draft.attachments,
		DetachedFiles:    draft.detachments,
		SupportedVersion: proto.Int32(protoVersion),
	}

	serialized, err := proto.Marshal(msg)
	if err != nil {
		panic("error while serialising candidate Message: " + err.Error())
	}

	s := fmt.Sprintf("%d of %d bytes", len(serialized), pond.MaxSerializedMessage)
	return s, len(serialized) > pond.MaxSerializedMessage
}
Пример #2
0
// Update the datastore with the user's current state.
func (server *Server) UpdateFrozenUser(client *Client, state *mumbleproto.UserState) {
	// Full sync If there's no userstate messgae provided, or if there is one, and
	// it includes a registration operation.
	user := client.user
	nanos := time.Now().Unix()
	if state == nil || state.UserId != nil {
		fu, err := user.Freeze()
		if err != nil {
			server.Fatal(err)
		}
		fu.LastActive = proto.Uint64(uint64(nanos))
		err = server.freezelog.Put(fu)
		if err != nil {
			server.Fatal(err)
		}
	} else {
		fu := &freezer.User{}
		fu.Id = proto.Uint32(user.Id)
		if state.ChannelId != nil {
			fu.LastChannelId = proto.Uint32(uint32(client.Channel.Id))
		}
		if state.TextureHash != nil {
			fu.TextureBlob = proto.String(user.TextureBlob)
		}
		if state.CommentHash != nil {
			fu.CommentBlob = proto.String(user.CommentBlob)
		}
		fu.LastActive = proto.Uint64(uint64(nanos))
		err := server.freezelog.Put(fu)
		if err != nil {
			server.Fatal(err)
		}
	}
	server.numLogOps += 1
}
Пример #3
0
// Encodes the SnapshotRecoveryRequest to a buffer. Returns the number of bytes
// written and any error that may have occurred.
func (req *SnapshotRecoveryRequest) encode(w io.Writer) (int, error) {

	protoPeers := make([]*protobuf.ProtoSnapshotRecoveryRequest_ProtoPeer, len(req.Peers))

	for i, peer := range req.Peers {
		protoPeers[i] = &protobuf.ProtoSnapshotRecoveryRequest_ProtoPeer{
			Name:             proto.String(peer.Name),
			ConnectionString: proto.String(peer.ConnectionString),
		}
	}

	pb := &protobuf.ProtoSnapshotRecoveryRequest{
		LeaderName: proto.String(req.LeaderName),
		LastIndex:  proto.Uint64(req.LastIndex),
		LastTerm:   proto.Uint64(req.LastTerm),
		Peers:      protoPeers,
		State:      req.State,
	}
	p, err := proto.Marshal(pb)
	if err != nil {
		return -1, err
	}

	return w.Write(p)
}
Пример #4
0
func (self *InterfaceForProject) PushMessage(interfaceCMD *business.Command) (resultPacket Packet, err error) {
	//1.从interfaceCMD 中解析出所需要的信息
	//2.处理,并且得到结果
	//3.把结果写入CMD,并且做成Packet 返回。

	//1.解析...................................
	if interfaceCMD.GetUid() == nil {
		feedbackCMD.Result = proto.Uint32(2)
		feedbackCMD.ResultDescription = proto.String("no uid")
		resultPacket = *MakeInterfacePacket(feedbackCMD, 102)
		return resultPacket, err
	}
	senderUid := interfaceCMD.GetUid()[0]
	dialogID := interfaceCMD.GetGroupid()
	if dialogID == 0 {
		feedbackCMD.Result = proto.Uint32(2)
		feedbackCMD.ResultDescription = proto.String("no dialogid")
		resultPacket = *MakeInterfacePacket(feedbackCMD, 102)
		return resultPacket, err
	}
	if interfaceCMD.GetMessage() == nil {
		feedbackCMD.Result = proto.Uint32(2)
		feedbackCMD.ResultDescription = proto.String("no message")
		resultPacket = *MakeInterfacePacket(feedbackCMD, 102)
		return resultPacket, err
	}
	message := interfaceCMD.GetMessage()[0]
	random := GenRandom()
	var (
		requestMess = &protocol.Message{
			Data:   proto.String(message),
			Random: proto.Uint32(random),
		}
		requestCMD = &protocol.Command{
			Sender:   proto.Uint64(senderUid), //sender's uid
			Receiver: proto.Uint64(dialogID),  //0=server
			Message:  requestMess,
		}
	)
	pushMessagePacket := *MakePacket(requestCMD, 2)
	_, fl := SessionTable[senderUid]
	if fl == false {
		//fmt.Println("uid no in")
		feedbackCMD.Result = proto.Uint32(1)
		feedbackCMD.ResultDescription = proto.String("sender isn't online")
		resultPacket = *MakeInterfacePacket(feedbackCMD, 102)
		return resultPacket, nil
	}

	SessionTable[senderUid].incoming <- pushMessagePacket
	feedbackCMD.Result = proto.Uint32(0)
	feedbackCMD.ResultDescription = proto.String("success")
	resultPacket = *MakeInterfacePacket(feedbackCMD, 102)
	return resultPacket, nil
	//2.处理...................................
	//2.1 从dialogID (act_dialog表---dialog表)       中得到receiverUid,若不为senderUid,则转发,或者存离线
	//2.2 查找receiverUid失败,则返回要求服务器先建群
	//3.打包...................................
}
Пример #5
0
func (h *Harvester) Harvest(output chan *FileEvent) {
	// TODO(sissel): Read the file
	// TODO(sissel): Emit FileEvent for each line to 'output'
	// TODO(sissel): Handle rotation
	// TODO(sissel): Sleep when there's nothing to do
	// TODO(sissel): Quit if we think the file is dead (file dev/inode changed, no data in X seconds)

	fmt.Printf("Starting harvester: %s\n", h.Path)

	file := h.open()
	defer file.Close()
	//info, _ := file.Stat()

	// TODO(sissel): Ask the registrar for the start position?
	// TODO(sissel): record the current file inode/device/etc

	var line uint64 = 0 // Ask registrar about the line number

	// get current offset in file
	offset, _ := file.Seek(0, os.SEEK_CUR)

	// TODO(sissel): Make the buffer size tunable at start-time
	reader := bufio.NewReaderSize(file, 16<<10) // 16kb buffer by default

	var read_timeout = 10 * time.Second
	last_read_time := time.Now()
	for {
		text, err := h.readline(reader, read_timeout)

		if err != nil {
			if err == io.EOF {
				// timed out waiting for data, got eof.
				// TODO(sissel): Check to see if the file was truncated
				// TODO(sissel): if last_read_time was more than 24 hours ago
				if age := time.Since(last_read_time); age > (24 * time.Hour) {
					// This file is idle for more than 24 hours. Give up and stop harvesting.
					fmt.Printf("Stopping harvest of %s; last change was %d seconds ago\n", h.Path, age.Seconds())
					return
				}
				continue
			} else {
				fmt.Printf("Unexpected state reading from %s; error: %s\n", h.Path, err)
				return
			}
		}
		last_read_time = time.Now()

		line++
		event := &FileEvent{
			Source: proto.String(h.Path),
			Offset: proto.Uint64(uint64(offset)),
			Line:   proto.Uint64(line),
			Text:   text,
		}
		offset += int64(len(*event.Text)) + 1 // +1 because of the line terminator

		output <- event // ship the new event downstream
	} /* forever */
}
Пример #6
0
func fillResult(result *subprocess.SubprocessResult, response *contester_proto.LocalExecutionResult) {
	if result.TotalProcesses > 0 {
		response.TotalProcesses = proto.Uint64(result.TotalProcesses)
	}
	response.ReturnCode = proto.Uint32(result.ExitCode)
	response.Flags = parseSuccessCode(result.SuccessCode)
	response.Time = parseTime(result)
	response.Memory = proto.Uint64(result.PeakMemory)
	response.StdOut, _ = contester_proto.NewBlob(result.Output)
	response.StdErr, _ = contester_proto.NewBlob(result.Error)
}
Пример #7
0
// Encodes the SnapshotRequest to a buffer. Returns the number of bytes
// written and any error that may have occurred.
func (req *SnapshotRequest) Encode(w io.Writer) (int, error) {
	pb := &protobuf.ProtoSnapshotRequest{
		LeaderName: proto.String(req.LeaderName),
		LastIndex:  proto.Uint64(req.LastIndex),
		LastTerm:   proto.Uint64(req.LastTerm),
	}
	p, err := proto.Marshal(pb)
	if err != nil {
		return -1, err
	}

	return w.Write(p)
}
Пример #8
0
// Encodes the SnapshotRecoveryResponse to a buffer. Returns the number of bytes
// written and any error that may have occurred.
func (req *SnapshotRecoveryResponse) encode(w io.Writer) (int, error) {
	pb := &protobuf.ProtoSnapshotRecoveryResponse{
		Term:        proto.Uint64(req.Term),
		Success:     proto.Bool(req.Success),
		CommitIndex: proto.Uint64(req.CommitIndex),
	}
	p, err := proto.Marshal(pb)
	if err != nil {
		return -1, err
	}

	return w.Write(p)
}
Пример #9
0
// Encodes the AppendEntriesResponse to a buffer. Returns the number of bytes
// written and any error that may have occurred.
func (resp *AppendEntriesResponse) encode(w io.Writer) (int, error) {
	pb := &protobuf.ProtoAppendEntriesResponse{
		Term:        proto.Uint64(resp.Term),
		Index:       proto.Uint64(resp.Index),
		CommitIndex: proto.Uint64(resp.CommitIndex),
		Success:     proto.Bool(resp.Success),
	}
	p, err := proto.Marshal(pb)
	if err != nil {
		return -1, err
	}

	return w.Write(p)
}
Пример #10
0
// Encodes the RequestVoteRequest to a buffer. Returns the number of bytes
// written and any error that may have occurred.
func (req *RequestVoteRequest) Encode(w io.Writer) (int, error) {
	pb := &protobuf.ProtoRequestVoteRequest{
		Term:          proto.Uint64(req.Term),
		LastLogIndex:  proto.Uint64(req.LastLogIndex),
		LastLogTerm:   proto.Uint64(req.LastLogTerm),
		CandidateName: proto.String(req.CandidateName),
	}
	p, err := proto.Marshal(pb)
	if err != nil {
		return -1, err
	}

	return w.Write(p)
}
Пример #11
0
func packBlock(nrows uint64, data []byte) (*block, error) {
	compressed, err := lzmaCompress(int64(len(data)), data)
	if err != nil {
		return nil, err
	}

	header := cbs_proto.Header{
		NumRows:             proto.Uint64(nrows),
		BlockSize:           proto.Uint64(uint64(len(data))),
		CompressedBlockSize: proto.Uint64(uint64(len(compressed))),
	}

	return &block{&header, compressed}, nil
}
func RPCAuthenticateWithKeyMessage(conn net.Conn, connection_data *structs.ConnData, packet_data *structs.PacketData) error {
	// Unmarshal the data
	msg := new(protocol.AuthenticateWithKeyMessage)
	err := proto.Unmarshal(packet_data.Content, msg)
	if err != nil {
		return err
	}

	// Generate a new connection-id based npid
	npid := structs.IdToNpid(connection_data.ConnectionId)

	// Fill in the connection data
	connection_data.Authenticated = true
	connection_data.IsServer = true
	connection_data.Token = ""
	connection_data.Npid = npid

	// Add connection to the storage
	storage.SetServerConnection(npid, connection_data)

	// Reply with the data
	return reply.Reply(conn, packet_data.Header.Id, &protocol.AuthenticateResultMessage{
		Result:       proto.Int32(0),
		Npid:         proto.Uint64(npid),
		SessionToken: []byte(""),
	})
}
Пример #13
0
func (sc *ServerClient) dispatch() {
	for p := range sc.in {
		if p.GetEnsureArrival() != 0 {
			sc.Send(&packet.Packet{
				ArrivalNotice: &packet.Packet_ArrivalNotice{
					PacketID: proto.Uint64(p.GetEnsureArrival()),
				},
			}, false)
		} else if an := p.GetArrivalNotice().GetPacketID(); an != 0 {
			sc.server.arrivalNotice(sc.addr, an)
			continue
		}

		if t := p.GetTestingPacket(); t != nil {
			switch t.GetType() {
			case packet.Packet_TestingPacket_Push:
			case packet.Packet_TestingPacket_Request:
				sc.Send(&packet.Packet{
					TestingPacket: &packet.Packet_TestingPacket{
						Type: packet.Packet_TestingPacket_Response.Enum(),
					},
				}, false)

			case packet.Packet_TestingPacket_Response:
			}
			continue
		}
		log.Println(sc.addr, p)
	}
}
Пример #14
0
func (c *clientCodec) WriteRequest(rpcreq *rpc.Request, param interface{}) error {
	rr := *rpcreq
	req := &Request{}

	c.mutex.Lock()
	req.Id = proto.Uint64(c.next)
	c.next++
	c.pending[*req.Id] = &rr
	c.mutex.Unlock()

	req.Method = proto.String(rpcreq.ServiceMethod)
	if msg, ok := param.(proto.Message); ok {
		body, err := proto.Marshal(msg)
		if err != nil {
			return err
		}
		req.Body = body
	} else {
		return fmt.Errorf("marshal request param error: %s", param)
	}

	f, err := proto.Marshal(req)
	if err != nil {
		return err
	}

	if err := write(c.w, f); err != nil {
		return err
	}

	return nil
}
Пример #15
0
func StatFile(name string, hash_it bool) (*contester_proto.FileStat, error) {
	result := &contester_proto.FileStat{}
	result.Name = &name
	info, err := os.Stat(name)
	if err != nil {
		// Handle ERROR_FILE_NOT_FOUND - return no error and nil instead of stat struct
		if IsStatErrorFileNotFound(err) {
			return nil, nil
		}

		return nil, NewError(err, "statFile", "os.Stat")
	}
	if info.IsDir() {
		result.IsDirectory = proto.Bool(true)
	} else {
		result.Size = proto.Uint64(uint64(info.Size()))
		if hash_it {
			checksum, err := HashFileString(name)
			if err != nil {
				return nil, NewError(err, "statFile", "hashFile")
			}
			result.Checksum = &checksum
		}
	}
	return result, nil
}
Пример #16
0
// TODO: Documentation
func (c *Client) Read() (*packet.Packet, error) {
	var buf [MaxPacketSize]byte
	parsed := new(packet.Packet)

	for {
		n, err := c.conn.Read(buf[:])
		if err != nil {
			return nil, err
		}

		if err = proto.Unmarshal(buf[:n], parsed); err != nil {
			return nil, err
		}

		if an := parsed.GetArrivalNotice().GetPacketID(); an != 0 {
			c.lock.Lock()
			delete(c.ensured, an)
			c.lock.Unlock()
			continue
		}

		if ensure := parsed.GetEnsureArrival(); ensure != 0 {
			c.Write(&packet.Packet{
				ArrivalNotice: &packet.Packet_ArrivalNotice{
					PacketID: proto.Uint64(ensure),
				},
			}, false)
		}

		return parsed, nil
	}

	panic("unreachable")
}
Пример #17
0
func createSubmit(db *sqlx.DB, sub *scannedSubmit, submitNo int) *tickets.Ticket_Submit {
	var result tickets.Ticket_Submit
	result.SubmitNumber = proto.Uint32(uint32(submitNo))
	if sub.Arrived > 0 {
		result.Arrived = proto.Uint64(uint64(sub.Arrived))
	}
	if result.Compiled = proto.Bool(sub.Compiled == 1); !result.GetCompiled() {
		return &result
	}
	if sub.SchoolMode != 0 {
		result.School = &tickets.Ticket_Submit_School{TestsTaken: proto.Uint32(uint32(sub.Taken)), TestsPassed: proto.Uint32(uint32(sub.Passed))}
	} else {
		var description string
		var test int64
		err := db.QueryRow("select ResultDesc.Description, Results.Test from Results, ResultDesc where "+
			"Results.UID = ? and ResultDesc.ID = Results.Result and not ResultDesc.Success order by Results.Test",
			sub.TestingID).Scan(&description, &test)
		switch {
		case err == sql.ErrNoRows:
			if sub.Passed != 0 && sub.Passed == sub.Taken {
				result.Acm = &tickets.Ticket_Submit_ACM{Result: proto.String("ACCEPTED")}
			}
		case err != nil:
			log.Fatal(err)
			return nil
		default:
			result.Acm = &tickets.Ticket_Submit_ACM{Result: &description, TestId: proto.Uint32(uint32(test))}
		}
	}
	return &result
}
Пример #18
0
func (s *summary) Write(out *dto.Metric) error {
	sum := &dto.Summary{}
	qs := make([]*dto.Quantile, 0, len(s.objectives))

	s.bufMtx.Lock()
	s.mtx.Lock()

	if len(s.hotBuf) != 0 {
		s.swapBufs(time.Now())
	}
	s.bufMtx.Unlock()

	s.flushColdBuf()
	sum.SampleCount = proto.Uint64(s.cnt)
	sum.SampleSum = proto.Float64(s.sum)

	for _, rank := range s.sortedObjectives {
		qs = append(qs, &dto.Quantile{
			Quantile: proto.Float64(rank),
			Value:    proto.Float64(s.headStream.Query(rank)),
		})
	}

	s.mtx.Unlock()

	if len(qs) > 0 {
		sort.Sort(quantSort(qs))
	}
	sum.Quantile = qs

	out.Summary = sum
	out.Label = s.labelPairs
	return nil
}
Пример #19
0
func (self *Client) SendBussiness(ziptype int32, datatype int32, data []byte) (uint64, string) {
	fun := "Client.SendBussiness"

	msgid, err := self.manager.Msgid()
	if err != nil {
		slog.Errorf("%s get msgid error:%s", fun, err)
		return 0, self.remoteaddr
	}

	buss := &pushproto.Talk{
		Type:     pushproto.Talk_BUSSINESS.Enum(),
		Msgid:    proto.Uint64(msgid),
		Ziptype:  proto.Int32(ziptype),
		Datatype: proto.Int32(datatype),
		Bussdata: data,
	}

	spb, err := proto.Marshal(buss)
	if err != nil {
		slog.Errorf("%s marshaling error: ", fun, err)
		return 0, self.remoteaddr
	}

	p := util.Packdata(spb)
	self.sendBussRetry(msgid, p)

	slog.Infof("%s client:%s send msgid:%d", fun, self, msgid)
	self.Send(p)

	return msgid, self.remoteaddr
}
Пример #20
0
func (db *Db) NewTransaction(cb func(b Block)) *Transaction {
	trx := &Transaction{
		Id: pb.Uint64(uint64(time.Now().UnixNano())), // TODO: put real id from nrv
	}
	cb(trx.newBlock())
	return trx
}
Пример #21
0
func (ut uploadTransfer) Request() *pond.Request {
	return &pond.Request{
		Upload: &pond.Upload{
			Id:   proto.Uint64(ut.id),
			Size: proto.Int64(ut.total),
		},
	}
}
Пример #22
0
func (h *Harvester) Harvest(output chan *FileEvent) {
	// TODO(sissel): Read the file
	// TODO(sissel): Emit FileEvent for each line to 'output'
	// TODO(sissel): Handle rotation
	// TODO(sissel): Sleep when there's nothing to do

	for {
		dummy := &FileEvent{
			Source: proto.String("/var/log/example"),
			Offset: proto.Uint64(0),
			Line:   proto.Uint64(0),
			Text:   proto.String("alskdjf laskdjf laskdfj laskdjf laskdjf lasdkfj asldkfj hello world!"),
		}
		output <- dummy
		time.Sleep(10 * time.Millisecond)
	}
}
Пример #23
0
func TestHeaderSize(t *testing.T) {
	header := &Header{Length: proto.Uint64(222)}
	buf, err := proto.Marshal(header)
	if err != nil {
		t.Error(err)
	}
	t.Log(len(buf))
}
Пример #24
0
// readingValue represents the state where the last byte read (now in
// p.currentByte) is the first byte of the sample value (i.e. a float).
func (p *Parser) readingValue() stateFn {
	// When we are here, we have read all the labels, so for the
	// infamous special case of a summary, we can finally find out
	// if the metric already exists.
	if p.currentMF.GetType() == dto.MetricType_SUMMARY {
		signature := model.LabelsToSignature(p.currentLabels)
		if summary := p.summaries[signature]; summary != nil {
			p.currentMetric = summary
		} else {
			p.summaries[signature] = p.currentMetric
			p.currentMF.Metric = append(p.currentMF.Metric, p.currentMetric)
		}
	} else {
		p.currentMF.Metric = append(p.currentMF.Metric, p.currentMetric)
	}
	if p.readTokenUntilWhitespace(); p.err != nil {
		return nil // Unexpected end of input.
	}
	value, err := strconv.ParseFloat(p.currentToken.String(), 64)
	if err != nil {
		// Create a more helpful error message.
		p.parseError(fmt.Sprintf("expected float as value, got %q", p.currentToken.String()))
		return nil
	}
	switch p.currentMF.GetType() {
	case dto.MetricType_COUNTER:
		p.currentMetric.Counter = &dto.Counter{Value: proto.Float64(value)}
	case dto.MetricType_GAUGE:
		p.currentMetric.Gauge = &dto.Gauge{Value: proto.Float64(value)}
	case dto.MetricType_UNTYPED:
		p.currentMetric.Untyped = &dto.Untyped{Value: proto.Float64(value)}
	case dto.MetricType_SUMMARY:
		// *sigh*
		if p.currentMetric.Summary == nil {
			p.currentMetric.Summary = &dto.Summary{}
		}
		switch {
		case p.currentIsSummaryCount:
			p.currentMetric.Summary.SampleCount = proto.Uint64(uint64(value))
		case p.currentIsSummarySum:
			p.currentMetric.Summary.SampleSum = proto.Float64(value)
		case !math.IsNaN(p.currentQuantile):
			p.currentMetric.Summary.Quantile = append(
				p.currentMetric.Summary.Quantile,
				&dto.Quantile{
					Quantile: proto.Float64(p.currentQuantile),
					Value:    proto.Float64(value),
				},
			)
		}
	default:
		p.err = fmt.Errorf("unexpected type for metric name %q", p.currentMF.GetName())
	}
	if p.currentByte == '\n' {
		return p.startOfLine
	}
	return p.startTimestamp
}
Пример #25
0
// Encodes the log entry to a buffer. Returns the number of bytes
// written and any error that may have occurred.
func (e *LogEntry) encode(w io.Writer) (int, error) {
	defer e.log.pBuffer.Reset()
	e.log.pLogEntry.Index = proto.Uint64(e.Index)
	e.log.pLogEntry.Term = proto.Uint64(e.Term)
	e.log.pLogEntry.CommandName = proto.String(e.CommandName)
	e.log.pLogEntry.Command = e.Command

	err := e.log.pBuffer.Marshal(e.log.pLogEntry)
	if err != nil {
		return -1, err
	}

	if _, err = fmt.Fprintf(w, "%8x\n", len(e.log.pBuffer.Bytes())); err != nil {
		return -1, err
	}

	return w.Write(e.log.pBuffer.Bytes())
}
Пример #26
0
func rename(roleid uint64, name string) error {
	req := &onlineproto.RenameReq{
		Account: proto.String(accountName),
		Name:    proto.String(roleName + "Rename"),
		Roleid:  proto.Uint64(roleid),
	}
	var rsp onlineproto.RenameRsp
	return sendAndRecv(&onlineServer, uint32(onlineproto.Command_CMD_RENAME_REQ), req, &rsp)
}
Пример #27
0
func parseTime(r *subprocess.SubprocessResult) *contester_proto.ExecutionResultTime {
	if r.UserTime == 0 && r.KernelTime == 0 && r.WallTime == 0 {
		return nil
	}

	result := &contester_proto.ExecutionResultTime{}

	if r.UserTime != 0 {
		result.UserTimeMicros = proto.Uint64(subprocess.GetMicros(r.UserTime))
	}
	if r.KernelTime != 0 {
		result.KernelTimeMicros = proto.Uint64(subprocess.GetMicros(r.KernelTime))
	}
	if r.WallTime != 0 {
		result.WallTimeMicros = proto.Uint64(subprocess.GetMicros(r.WallTime))
	}
	return result
}
Пример #28
0
func loginGS(s *Server, name string, roleid uint64) error {
	req := &gsproto.LoginReq{
		Account: proto.String(accountName),
		Name:    proto.String(name),
		Token:   []byte{0x44, 0x45, 0x46, 0x47},
		Roleid:  proto.Uint64(roleid),
	}
	var rsp gsproto.LoginRsp
	return sendAndRecv(s, uint32(gsproto.Command_CMD_LOGIN_REQ), req, &rsp)
}
Пример #29
0
func main() {
	context, _ := zmq.NewContext()
	socket, _ := context.NewSocket(zmq.REQ)
	defer context.Close()
	defer socket.Close()

	fmt.Printf("Connecting\n")
	socket.Connect("tcp://localhost:5555")

	f := &lumberjack.FileEvent{}
	f.Source = proto.String("/var/log/message")
	f.Offset = proto.Uint64(0)
	f.Line = proto.Uint64(0)
	f.Text = proto.String("hello world")

	for i := 0; ; i++ {
		start := time.Now()
		data, _ := proto.Marshal(f)
		marshal_time := time.Since(start)

		start = time.Now()
		socket.Send(data, 0)
		send_time := time.Since(start)

		start = time.Now()
		reply, _ := socket.Recv(0)
		recv_time := time.Since(start)

		start = time.Now()
		r := &lumberjack.FileEvent{}
		_ = proto.Unmarshal(reply, r)
		unmarshal_time := time.Since(start)
		if i == 10000 {
			fmt.Printf("Received: %v\n", r)
			fmt.Printf("Marshal: %d\n", marshal_time.Nanoseconds())
			fmt.Printf("Send: %d\n", send_time.Nanoseconds())
			fmt.Printf("Recv: %d\n", recv_time.Nanoseconds())
			fmt.Printf("Unmarshal: %d\n", unmarshal_time.Nanoseconds())
			i = 0
		}
	}
}
Пример #30
0
// Sends a chat message to the given friend. Chatrooms/Group chats are not supported yet.
func (s *Social) SendMessage(to SteamId, message string, entryType EChatEntryType) {
	if to.GetAccountType() != int32(EAccountType_Individual) && to.GetAccountType() != int32(EAccountType_ConsoleUser) {
		panic("Messages to users other than individuals or consoles are not supported yet.")
	}

	s.client.Write(NewClientMsgProtobuf(EMsg_ClientFriendMsg, &CMsgClientFriendMsg{
		Steamid:       proto.Uint64(to.ToUint64()),
		ChatEntryType: proto.Int32(int32(entryType)),
		Message:       []byte(message),
	}))
}