func (self *ProtoProc) procRouteMessageP2P(cmd protocol.Cmd, session *libnet.Session) error { log.Info("procRouteMessageP2P") var err error send2ID := cmd.GetArgs()[0] send2Msg := cmd.GetArgs()[1] fromID := cmd.GetArgs()[2] uuid := cmd.GetArgs()[3] _, err = common.GetSessionFromCID(self.msgServer.sessionCache, send2ID) if err != nil { log.Warningf("no ID : %s", send2ID) return err } resp := protocol.NewCmdSimple(protocol.RESP_MESSAGE_P2P_CMD) resp.AddArg(send2Msg) resp.AddArg(fromID) // add uuid resp.AddArg(uuid) if self.msgServer.sessions[send2ID] != nil { self.msgServer.sessions[send2ID].Send(libnet.Json(resp)) if err != nil { log.Fatalln(err.Error()) } } return nil }
func (self *ProtoProc) procSendMsgP2P(cmd protocol.Cmd, session *libnet.Session) error { glog.Info("procSendMsgP2P") var err error send2ID := cmd.GetArgs()[0] send2Msg := cmd.GetArgs()[1] glog.Info(send2Msg) self.Monitor.readMutex.Lock() defer self.Monitor.readMutex.Unlock() store_session, err := common.GetSessionFromCID(self.Monitor.sessionStore, send2ID) if err != nil { glog.Warningf("no ID : %s", send2ID) return err } glog.Info(store_session.MsgServerAddr) cmd.ChangeCmdName(protocol.ROUTE_MESSAGE_P2P_CMD) err = self.Monitor.msgServerClientMap[store_session.MsgServerAddr].Send(libnet.Json(cmd)) if err != nil { glog.Error("error:", err) return err } return nil }
func (self *ProtoProc) procSendMsgP2P(cmd protocol.Cmd, session *libnet.Session) error { log.Info("procSendMsgP2P") var err error send2ID := cmd.GetArgs()[0] send2Msg := cmd.GetArgs()[1] log.Info(send2Msg) self.Router.readMutex.Lock() defer self.Router.readMutex.Unlock() cacheSession, err := common.GetSessionFromCID(self.Router.sessionCache, send2ID) if err != nil { log.Warningf("no ID in cache : %s", send2ID) storeSession, err := self.Router.mongoStore.GetSessionFromCid(mongo_store.DATA_BASE_NAME, mongo_store.TOPIC_INFO_COLLECTION, send2ID) if err != nil { return err } log.Info(storeSession.MsgServerAddr) cmd.ChangeCmdName(protocol.ROUTE_MESSAGE_P2P_CMD) err = self.Router.msgServerClientMap[storeSession.MsgServerAddr].Send(libnet.Json(cmd)) if err != nil { log.Error("error:", err) return err } } else { log.Info(cacheSession.MsgServerAddr) cmd.ChangeCmdName(protocol.ROUTE_MESSAGE_P2P_CMD) err = self.Router.msgServerClientMap[cacheSession.MsgServerAddr].Send(libnet.Json(cmd)) if err != nil { log.Error("error:", err) return err } } return nil }
func (self *ProtoProc) procSendMessageP2P(cmd protocol.Cmd, session *libnet.Session) error { glog.Info("procSendMessageP2P") var err error send2ID := cmd.GetArgs()[0] send2Msg := cmd.GetArgs()[1] fromID := cmd.GetArgs()[2] store_session, err := common.GetSessionFromCID(self.msgServer.sessionStore, send2ID) if err != nil { glog.Warningf("no ID : %s", send2ID) return err } if self.msgServer.sessions[send2ID] == nil { //offline glog.Info(send2ID + " | is offline") exist, err := self.msgServer.offlineMsgStore.IsKeyExist(send2ID) if exist.(int64) == 0 { tmp := storage.NewOfflineMsgStoreData(send2ID) tmp.AddMsg(storage.NewOfflineMsgData(send2Msg, fromID)) self.msgServer.offlineMsgStore.Set(tmp) if err != nil { glog.Error(err.Error()) return err } } else { omrd, err := common.GetOfflineMsgFromOwnerName(self.msgServer.offlineMsgStore, send2ID) if err != nil { glog.Error(err.Error()) return err } omrd.AddMsg(storage.NewOfflineMsgData(send2Msg, fromID)) self.msgServer.offlineMsgStore.Set(omrd) if err != nil { glog.Error(err.Error()) return err } } } if store_session.MsgServerAddr == self.msgServer.cfg.LocalIP { glog.Info("in the same server") resp := protocol.NewCmdSimple(protocol.RESP_MESSAGE_P2P_CMD) resp.AddArg(send2Msg) resp.AddArg(fromID) if self.msgServer.sessions[send2ID] != nil { self.msgServer.sessions[send2ID].Send(libnet.Json(resp)) if err != nil { glog.Error(err.Error()) } } } else { if self.msgServer.channels[protocol.SYSCTRL_SEND] != nil { _, err = self.msgServer.channels[protocol.SYSCTRL_SEND].Channel.Broadcast(libnet.Json(cmd)) if err != nil { glog.Error(err.Error()) return err } } } return nil }
func (self *ProtoProc) procSendMessageP2P(cmd protocol.Cmd, session *libnet.Session) error { log.Info("procSendMessageP2P") var err error send2ID := cmd.GetArgs()[0] send2Msg := cmd.GetArgs()[1] fromID := cmd.GetArgs()[2] store_session, err := common.GetSessionFromCID(self.msgServer.sessionCache, send2ID) if err != nil { log.Warningf("no ID : %s", send2ID) return err } uuid := common.NewV4().String() log.Info("uuid : ", uuid) uuidTmpMap := make(map[string]bool) uuidTmpMap[uuid] = false self.msgServer.p2pAckStatus[fromID] = uuidTmpMap if self.msgServer.sessions[send2ID] == nil { //offline log.Info(send2ID + " | is offline") exist, err := self.msgServer.offlineMsgCache.IsKeyExist(send2ID) if exist.(int64) == 0 { tmp := redis_store.NewOfflineMsgCacheData(send2ID) tmp.AddMsg(redis_store.NewOfflineMsgData(send2Msg, fromID, uuid)) self.msgServer.offlineMsgCache.Set(tmp) if err != nil { log.Error(err.Error()) return err } } else { omrd, err := common.GetOfflineMsgFromOwnerName(self.msgServer.offlineMsgCache, send2ID) if err != nil { log.Error(err.Error()) return err } omrd.AddMsg(redis_store.NewOfflineMsgData(send2Msg, fromID, uuid)) self.msgServer.offlineMsgCache.Set(omrd) if err != nil { log.Error(err.Error()) return err } } } if store_session.MsgServerAddr == self.msgServer.cfg.LocalIP { log.Info("in the same server") resp := protocol.NewCmdSimple(protocol.RESP_MESSAGE_P2P_CMD) resp.AddArg(send2Msg) resp.AddArg(fromID) // add uuid resp.AddArg(uuid) if self.msgServer.sessions[send2ID] != nil { self.msgServer.sessions[send2ID].Send(libnet.Json(resp)) if err != nil { log.Error(err.Error()) } } } else { if self.msgServer.channels[protocol.SYSCTRL_SEND] != nil { //add uuid cmd.AddArg(uuid) _, err = self.msgServer.channels[protocol.SYSCTRL_SEND].Channel.Broadcast(libnet.Json(cmd)) if err != nil { log.Error(err.Error()) return err } } } return nil }