Ejemplo n.º 1
0
func (self *serverConn) SendMessage(msg *rpc.Message, id string, extra map[string]string, tryDigest bool) error {
	if msg == nil {
		cmd := &proto.Command{
			Type: proto.CMD_EMPTY,
		}
		if len(id) > 0 {
			cmd.Params = []string{id}
		}
		return self.cmdio.WriteCommand(cmd, false)
	}
	sz := msg.Size()
	if tryDigest && self.shouldDigest(sz) {
		container := &rpc.MessageContainer{
			Id:      id,
			Message: msg,
		}
		return self.writeDigest(container, extra, sz)
	}
	cmd := &proto.Command{
		Type:    proto.CMD_DATA,
		Message: msg,
	}
	cmd.Params = []string{id}
	return self.cmdio.WriteCommand(cmd, self.shouldCompress(sz))
}
Ejemplo n.º 2
0
func (self *clientConn) SendMessageToServer(msg *rpc.Message) error {
	compress := self.shouldCompress(msg.Size())

	cmd := &proto.Command{}
	cmd.Message = msg
	cmd.Type = proto.CMD_DATA
	err := self.cmdio.WriteCommand(cmd, compress)
	return err
}
Ejemplo n.º 3
0
func (self *clientConn) SendMessageToUsers(msg *rpc.Message, ttl time.Duration, service string, receiver ...string) error {
	if len(receiver) == 0 {
		return nil
	}
	cmd := &proto.Command{}
	cmd.Type = proto.CMD_FWD_REQ
	cmd.Params = make([]string, 2, 3)
	cmd.Params[0] = fmt.Sprintf("%v", ttl)
	cmd.Params[1] = strings.Join(receiver, ",")
	if len(service) > 0 && service != self.Service() {
		cmd.Params = append(cmd.Params, service)
	}
	cmd.Message = msg
	compress := self.shouldCompress(msg.Size())
	return self.cmdio.WriteCommand(cmd, compress)
}
Ejemplo n.º 4
0
func (self *serverConn) ForwardMessage(sender, senderService string, msg *rpc.Message, id string, tryDigest bool) error {
	sz := msg.Size()
	if sz == 0 {
		return nil
	}
	if tryDigest && self.shouldDigest(sz) {
		container := &rpc.MessageContainer{
			Id:            id,
			Sender:        sender,
			SenderService: senderService,
			Message:       msg,
		}
		return self.writeDigest(container, nil, sz)
	}
	cmd := &proto.Command{
		Type:    proto.CMD_FWD,
		Message: msg,
	}
	cmd.Params = []string{sender, senderService, id}
	return self.cmdio.WriteCommand(cmd, self.shouldCompress(sz))
}