Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

124 lines (110 sloc) 3.132 kb
#ifndef __LIBF2F_GREYNET_MESSAGE_H__
#define __LIBF2F_GREYNET_MESSAGE_H__
#include "playdar/resolver_query.hpp"
#include "playdar/playdar_plugin_include.h"
#include "libf2f/message.h"
#define PING 0
#define PONG 1
#define IDENT 2
#define QUERY 3
#define QUERYRESULT 4
#define QUERYSTOP 5
#define SIDREQUEST 6
#define SIDDATA 7
#define SIDFAIL 8
#define SIDHEADERS 9
/// TODO msg abstraction/oo-ness is half-assed atm.
/// maybe we should be passing a MsgFactory to the router, then just have one
/// polymorphic call to message_received(<msgtype> msgp).
/// either way, we need a big switch statement for msg types somewhere tho :|
class PongMessage : public libf2f::Message
{
public:
PongMessage(const std::string& uuid)
{
libf2f::message_header h;
memcpy( &h.guid, uuid.data(), 36 );
h.type = PONG;
h.ttl = 1;
h.hops = 0;
h.length = 0;
m_header = h;
m_payload = 0;
}
};
class PingMessage : public libf2f::Message
{
public:
PingMessage(const std::string& uuid)
{
libf2f::message_header h;
memcpy( &h.guid, uuid.data(), 36 );
h.type = PING;
h.ttl = 1;
h.hops = 0;
h.length = 0;
m_header = h;
m_payload = 0;
}
};
class IdentMessage : public libf2f::Message
{
public:
IdentMessage(const std::string &body, const std::string& uuid)
{
libf2f::message_header h;
memcpy( &h.guid, uuid.data(), 36 );
h.type = IDENT;
h.ttl = 1;
h.hops = 0;
h.length = htonl(body.length());
m_header = h;
malloc_payload();
memcpy( m_payload, body.data(), body.length() );
}
};
class QueryMessage : public libf2f::Message
{
public:
QueryMessage(playdar::rq_ptr rq, const std::string& uuid)
{
libf2f::message_header h;
memcpy( &h.guid, uuid.data(), 36 );
h.type = QUERY;
h.ttl = 1;
h.hops = 0;
using namespace json_spirit;
Object jq = rq->get_json();
std::ostringstream querystr;
write( jq, querystr );
std::string pl = querystr.str();
h.length = htonl( pl.length() );
m_header = h;
malloc_payload();
memcpy( m_payload, pl.c_str(), pl.length() );
}
};
class QueryResultMessage : public libf2f::Message
{
public:
QueryResultMessage(playdar::query_uid qid, playdar::ri_ptr rip, const std::string& uuid)
{
libf2f::message_header h;
memcpy( &h.guid, uuid.data(), 36 );
h.type = QUERYRESULT;
h.ttl = 1;
h.hops = 0;
using namespace json_spirit;
Object response;
response.push_back( Pair("qid", qid) );
response.push_back( Pair("result", rip->get_json()) );
std::ostringstream ss;
write( response, ss );
std::string pl = ss.str();
h.length = htonl( pl.length() );
m_header = h;
malloc_payload();
memcpy( m_payload, pl.c_str(), pl.length() );
}
};
#endif
Jump to Line
Something went wrong with that request. Please try again.