Skip to content
Browse files

CumulusEdge development

  • Loading branch information...
1 parent 1f1e418 commit 321502ca2341094dec22506fc04fb3bd4c9b1d53 @cumulusdev cumulusdev committed Jan 17, 2012
View
5 CumulusLib/include/Edges.h
@@ -71,12 +71,17 @@ class Edges {
Iterator end();
Poco::UInt32 count();
+ Edge* operator()(const std::string& address);
Edge* operator()(const Poco::Net::SocketAddress& address);
private:
std::map<std::string,Edge*>& _edges;
};
+inline Edge* Edges::operator()(const Poco::Net::SocketAddress& address) {
+ return this->operator ()(address.toString());
+}
+
inline Poco::UInt32 Edges::count() {
return _edges.size();
}
View
2 CumulusLib/include/RTMFPServer.h
@@ -64,6 +64,7 @@ class RTMFPServer : private Gateway,protected Handler,private Startable {
RTMFPServer(const std::string& name);
virtual void onStart(){}
virtual void onStop(){}
+ virtual void displayCount(Poco::UInt32 sessions);
Session* findSession(Poco::UInt32 id);
bool prerun();
@@ -73,7 +74,6 @@ class RTMFPServer : private Gateway,protected Handler,private Startable {
void destroySession(Session& session);
Handshake _handshake;
- //BridgeHandshake _bridgeHandshake;
Poco::UInt16 _port;
Poco::Net::DatagramSocket _socket;
View
1 CumulusLib/include/RTMFPServerEdge.h
@@ -58,6 +58,7 @@ class RTMFPServerEdge : private RTMFPServer {
void destroySession(Session& session);
void repeatCookie(Poco::UInt32 farId,Cookie& cookie);
void run(const volatile bool& terminate);
+ void displayCount(Poco::UInt32 sessions);
ServerConnection _serverConnection;
View
3 CumulusLib/include/ServerSession.h
@@ -26,6 +26,9 @@
namespace Cumulus {
+#define SESSION_BY_EDGE 1
+
+
class Attempt {
public:
Attempt() : count(0) {
View
2 CumulusLib/include/Session.h
@@ -44,6 +44,8 @@ class Session {
const bool checked;
const bool died;
+ Poco::UInt8 flags;
+
bool middleDump;
virtual void manage(){}
View
4 CumulusLib/sources/Edges.cpp
@@ -38,8 +38,8 @@ void Edge::update() {
_timeLastExchange.update();
}
-Edge* Edges::operator()(const SocketAddress& address) {
- Iterator it = _edges.find(address.toString());
+Edge* Edges::operator()(const string& address) {
+ Iterator it = _edges.find(address);
if(it==_edges.end())
return NULL;
return it->second;
View
2 CumulusLib/sources/Handshake.cpp
@@ -319,6 +319,7 @@ UInt8 Handshake::handshakeHandler(UInt8 id,PacketReader& request,PacketWriter& r
cookie.computeKeys(&publicKey[0],publicKey.size(),request.current(),size,decryptKey,encryptKey);
} else {
+ // edge
pDecryptKey=NULL;
pEncryptKey=NULL;
memcpy((UInt8*)peer.id,request.current(),ID_SIZE);
@@ -336,6 +337,7 @@ UInt8 Handshake::handshakeHandler(UInt8 id,PacketReader& request,PacketWriter& r
string address;
if(id==0x39) {
// Session by edge
+ session.flags |= SESSION_BY_EDGE;
Edge* pEdge = _invoker.edges(peer.address);
if(!pEdge)
ERROR("Edge session creation by an unknown server edge %s",peer.address.toString().c_str())
View
6 CumulusLib/sources/RTMFPServer.cpp
@@ -355,10 +355,14 @@ bool RTMFPServer::realTime(bool& terminate) {
void RTMFPServer::manage() {
_handshake.manage();
if(_sessions.manage())
- INFO("%u clients",clients.count());
+ displayCount(_sessions.count());
if(!_middle && !_pCirrus && _timeLastManage.isElapsed(20000))
WARN("Process management has lasted more than 20ms : %ums",UInt32(_timeLastManage.elapsed()/1000));
}
+void RTMFPServer::displayCount(UInt32 sessions) {
+ INFO("%u clients",clients.count());
+}
+
} // namespace Cumulus
View
8 CumulusLib/sources/RTMFPServerEdge.cpp
@@ -24,7 +24,7 @@ using namespace Poco::Net;
namespace Cumulus {
-RTMFPServerEdge::RTMFPServerEdge() : RTMFPServer("RTMFPServerBridge"),_serverConnection(*this,_handshake) {
+RTMFPServerEdge::RTMFPServerEdge() : RTMFPServer("RTMFPServerEdge"),_serverConnection(*this,_handshake) {
}
@@ -36,7 +36,7 @@ EdgeSession* RTMFPServerEdge::findEdgeSession(UInt32 id) {
EdgeSession* pSession= dynamic_cast<EdgeSession*>(findSession(id));
if(pSession)
return pSession;
- ERROR("Unknown edge session %u",id);
+ WARN("Unknown edge session %u",id);
return NULL;
}
@@ -181,5 +181,9 @@ void RTMFPServerEdge::manage() {
(bool&)_serverConnection.died=true;
}
+void RTMFPServerEdge::displayCount(UInt32 sessions) {
+ INFO("%u clients",sessions);
+}
+
} // namespace Cumulus
View
2 CumulusLib/sources/ServerSession.cpp
@@ -338,7 +338,7 @@ void ServerSession::packetHandler(PacketReader& packet) {
if(peer.addresses.size()==0) {
CRITIC("Session %u has no any addresses!",id);
peer.addresses.push_front(peer.address.toString());
- } else if(peer.addresses.front()!=peer.address) {
+ } else if(!(flags&SESSION_BY_EDGE) && peer.addresses.front()!=peer.address) {
INFO("Session %u has changed its public address",id);
peer.addresses.pop_front();
peer.addresses.push_front(peer.address.toString());
View
2 CumulusLib/sources/Session.cpp
@@ -30,7 +30,7 @@ Session::Session(UInt32 id,
const Peer& peer,
const UInt8* decryptKey,
const UInt8* encryptKey) :
- died(false),checked(false),id(id),farId(farId),peer(peer),aesDecrypt(decryptKey,AESEngine::DECRYPT),aesEncrypt(encryptKey,AESEngine::ENCRYPT),_pSocket(NULL),middleDump(false) {
+ flags(0),died(false),checked(false),id(id),farId(farId),peer(peer),aesDecrypt(decryptKey,AESEngine::DECRYPT),aesEncrypt(encryptKey,AESEngine::ENCRYPT),_pSocket(NULL),middleDump(false) {
}
View
14 CumulusServer/sources/LUAEdges.cpp
@@ -31,10 +31,10 @@ int LUAEdges::Pairs(lua_State* pState) {
else {
lua_newtable(pState);
Edges::Iterator it;
- /* TODO for(it=edges.begin();it!=edges.end();++it) {
- SCRIPT_WRITE_PERSISTENT_OBJECT(Edge,LUAEdge,*it->second)
- lua_setfield(pState,-2,Util::FormatHex(it->second->id,ID_SIZE).c_str());
- }*/
+ for(it=edges.begin();it!=edges.end();++it) {
+ SCRIPT_WRITE_NUMBER(it->second->count)
+ lua_setfield(pState,-2,it->first.c_str());
+ }
}
SCRIPT_CALLBACK_RETURN
}
@@ -46,6 +46,12 @@ int LUAEdges::Get(lua_State *pState) {
SCRIPT_WRITE_FUNCTION(&LUAEdges::Pairs)
else if(name=="count")
SCRIPT_WRITE_NUMBER(edges.count())
+ else if(name=="(") {
+ SCRIPT_READ_STRING(address,"")
+ Edge* pEdge = edges(address);
+ if(pEdge)
+ SCRIPT_WRITE_NUMBER(pEdge->count)
+ }
SCRIPT_CALLBACK_RETURN
}

0 comments on commit 321502c

Please sign in to comment.
Something went wrong with that request. Please try again.