Changeset 17 in chevmsgr


Ignore:
Timestamp:
11/22/15 19:53:51 (8 years ago)
Author:
cheese
Message:

msg.cpp에 SecureSocket 추가
서버 암호통신 구현
client 일부 수정

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/msg.hpp

    r16 r17  
    22
    33#include "cf/logger.h"
     4#include "cf/network.h"
    45
    56#include "json.h"
     7#include "crypto.h"
    68
    79#include <iostream>
     
    164166    return concat;
    165167}
     168
     169
     170class SecureSocket
     171{
     172private :
     173    cf::network::tcp * sock;
     174    crypto aria;
     175
     176public :
     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  
    22
    33#include <string>
     4#include <list>
    45#include <vector>
    56
     
    3637private:
    3738    cf::task::mutex                 mutex;
    38     std::vector<Protocol::Message>  messageQ;
     39    std::list<Protocol::Message>    messageQ;
    3940
    4041public:
  • trunk/msgsrv.cpp

    r16 r17  
    1616// --------------------------------------------------------------
    1717
    18 typedef struct LoginSession
    19 {
    20     cf::network::tcp * sock;
    21     cf::bin key;
    22 } LoginSession;
    23 std::map<std::string, LoginSession> gOnlineUsers;
     18std::map<std::string, SecureSocket> gOnlineUsers;
    2419std::map<std::string, std::vector<std::string> > gSessionMap;
    2520
     
    368363        cf::bin key = crypto().sha256(seed);
    369364
    370         LoginSession loginSess;
    371 
    372         loginSess.sock = &sock;
    373         loginSess.key = key;
    374         gOnlineUsers[id] = loginSess;
     365        gOnlineUsers[id] = SecureSocket(&sock, key);
    375366    }
    376367
     
    393384
    394385        if (sender != id && isOnline(id))
    395             gOnlineUsers[id].sock->send(serialized);
     386            gOnlineUsers[id].send(serialized);
    396387
    397388        result = true;
     
    427418        std::string id = idList[iter];
    428419        if (isOnline(id))
    429             gOnlineUsers[id].sock->send(serialized);
     420            gOnlineUsers[id].send(serialized);
    430421
    431422        result = true;
Note: See TracChangeset for help on using the changeset viewer.