Changeset 17 in chevmsgr
Legend:
- Unmodified
- Added
- Removed
-
trunk/msg.hpp
r16 r17 2 2 3 3 #include "cf/logger.h" 4 #include "cf/network.h" 4 5 5 6 #include "json.h" 7 #include "crypto.h" 6 8 7 9 #include <iostream> … … 164 166 return concat; 165 167 } 168 169 170 class SecureSocket 171 { 172 private : 173 cf::network::tcp * sock; 174 crypto aria; 175 176 public : 177 SecureSocket() {} 178 SecureSocket(cf::network::tcp * sock, cf::bin & key) 179 { 180 init(sock, key); 181 } 182 183 void init(cf::network::tcp * sock, cf::bin & key) 184 { 185 this->sock = sock; 186 aria.setKey(key); 187 } 188 189 void send(const std::string & msg) 190 { 191 sock->send(aria.encrypt(cf::bin(msg))); 192 } 193 194 std::string receive() 195 { 196 return aria.decrypt(sock->receive()).toString(); 197 } 198 199 void close() 200 { 201 sock->close(); 202 } 203 }; -
trunk/msgclnt.h
r14 r17 2 2 3 3 #include <string> 4 #include <list> 4 5 #include <vector> 5 6 … … 36 37 private: 37 38 cf::task::mutex mutex; 38 std:: vector<Protocol::Message> messageQ;39 std::list<Protocol::Message> messageQ; 39 40 40 41 public: -
trunk/msgsrv.cpp
r16 r17 16 16 // -------------------------------------------------------------- 17 17 18 typedef struct LoginSession 19 { 20 cf::network::tcp * sock; 21 cf::bin key; 22 } LoginSession; 23 std::map<std::string, LoginSession> gOnlineUsers; 18 std::map<std::string, SecureSocket> gOnlineUsers; 24 19 std::map<std::string, std::vector<std::string> > gSessionMap; 25 20 … … 368 363 cf::bin key = crypto().sha256(seed); 369 364 370 LoginSession loginSess; 371 372 loginSess.sock = &sock; 373 loginSess.key = key; 374 gOnlineUsers[id] = loginSess; 365 gOnlineUsers[id] = SecureSocket(&sock, key); 375 366 } 376 367 … … 393 384 394 385 if (sender != id && isOnline(id)) 395 gOnlineUsers[id].s ock->send(serialized);386 gOnlineUsers[id].send(serialized); 396 387 397 388 result = true; … … 427 418 std::string id = idList[iter]; 428 419 if (isOnline(id)) 429 gOnlineUsers[id].s ock->send(serialized);420 gOnlineUsers[id].send(serialized); 430 421 431 422 result = true;
Note:
See TracChangeset
for help on using the changeset viewer.