Added SystemExternalAccess Function to RPC.

This provides ExternalPort + DHTKey to Client. To be used to find and connect - even if Dynamic IP address changes :)



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6004 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2012-12-17 19:15:04 +00:00
parent 97e9458f36
commit 766d156315
9 changed files with 959 additions and 10 deletions

View File

@ -161,6 +161,13 @@ p3BitDht::~p3BitDht()
}
bool p3BitDht::getOwnDhtId(std::string &ownDhtId)
{
bdStdPrintNodeId(ownDhtId, &(mOwnDhtId), false);
return true;
}
void p3BitDht::setupConnectBits(UdpStunner *dhtStunner, UdpStunner *proxyStunner, UdpRelayReceiver *relay)
{
mDhtStunner = dhtStunner;

View File

@ -168,6 +168,8 @@ virtual std::string getUdpAddressString();
virtual void getDhtRates(float &read, float &write);
virtual void getRelayRates(float &read, float &write, float &relay);
virtual bool getOwnDhtId(std::string &ownDhtId);
/***********************************************************************************************
********** External RsDHT Interface (defined in libretroshare/src/retroshare/rsdht.h) *********
************************************************************************************************/

View File

@ -190,6 +190,9 @@ virtual int setRelayMode(uint32_t mode) = 0;
virtual int getRelayAllowance(int classIdx, uint32_t &count, uint32_t &bandwidth) = 0;
virtual int setRelayAllowance(int classIdx, uint32_t count, uint32_t bandwidth) = 0;
// So we can provide to clients.
virtual bool getOwnDhtId(std::string &ownDhtId) = 0;
#if 0
virtual std::string getPeerStatusString();

View File

@ -48,6 +48,9 @@
#include "rpc/rpcsetup.h"
// NASTY GLOBAL VARIABLE HACK - NEED TO THINK OF A BETTER SYSTEM.
#include "rpc/proto/rpcprotosystem.h"
#endif
/* Basic instructions for running libretroshare as background thread.
@ -108,7 +111,10 @@ int main(int argc, char **argv)
std::string sshRsaFile = "";
std::string sshPortStr = "7022";
while((c = getopt(argc, argv,"ChTL:P:K:GS::")) != -1)
uint16_t extPort = 0;
bool extPortSet = false;
while((c = getopt(argc, argv,"ChTL:P:K:GS::E:")) != -1)
{
switch(c)
{
@ -124,6 +130,11 @@ int main(int argc, char **argv)
}
strictCheck = false;
break;
case 'E':
extPort = atoi(optarg);
extPortSet = true;
strictCheck = false;
break;
case 'H':
enableSshHtml = true;
strictCheck = false;
@ -158,6 +169,7 @@ int main(int argc, char **argv)
std::cerr << "\t-G Generate a Password Hash for SSH Server" << std::endl;
std::cerr << "\t-T Enable Terminal Interface" << std::endl;
std::cerr << "\t-S [port] Enable SSH Server, optionally specify port" << std::endl;
std::cerr << "\t-E <port> Specify Alternative External Port (provided to Clients)" << std::endl;
std::cerr << "\t-L <user> Specify SSH login user (default:user)" << std::endl;
std::cerr << "\t-P <pwdhash> Enable SSH login via Password" << std::endl;
std::cerr << "\t-C Enable RPC Protocol (requires -S too)" << std::endl;
@ -364,6 +376,13 @@ int main(int argc, char **argv)
ssh->adduserpwdhash(sshUser, sshPwdHash);
}
if (!extPortSet)
{
extPort = atoi(sshPortStr.c_str());
}
// NASTY GLOBAL VARIABLE HACK - NEED TO THINK OF A BETTER SYSTEM.
RpcProtoSystem::mExtPort = extPort;
}

View File

@ -32,6 +32,12 @@ const ::google::protobuf::EnumDescriptor* RequestSystemQuit_QuitCode_descriptor_
const ::google::protobuf::Descriptor* ResponseSystemQuit_descriptor_ = NULL;
const ::google::protobuf::internal::GeneratedMessageReflection*
ResponseSystemQuit_reflection_ = NULL;
const ::google::protobuf::Descriptor* RequestSystemExternalAccess_descriptor_ = NULL;
const ::google::protobuf::internal::GeneratedMessageReflection*
RequestSystemExternalAccess_reflection_ = NULL;
const ::google::protobuf::Descriptor* ResponseSystemExternalAccess_descriptor_ = NULL;
const ::google::protobuf::internal::GeneratedMessageReflection*
ResponseSystemExternalAccess_reflection_ = NULL;
const ::google::protobuf::EnumDescriptor* RequestMsgIds_descriptor_ = NULL;
const ::google::protobuf::EnumDescriptor* ResponseMsgIds_descriptor_ = NULL;
@ -109,6 +115,37 @@ void protobuf_AssignDesc_system_2eproto() {
::google::protobuf::DescriptorPool::generated_pool(),
::google::protobuf::MessageFactory::generated_factory(),
sizeof(ResponseSystemQuit));
RequestSystemExternalAccess_descriptor_ = file->message_type(4);
static const int RequestSystemExternalAccess_offsets_[1] = {
};
RequestSystemExternalAccess_reflection_ =
new ::google::protobuf::internal::GeneratedMessageReflection(
RequestSystemExternalAccess_descriptor_,
RequestSystemExternalAccess::default_instance_,
RequestSystemExternalAccess_offsets_,
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(RequestSystemExternalAccess, _has_bits_[0]),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(RequestSystemExternalAccess, _unknown_fields_),
-1,
::google::protobuf::DescriptorPool::generated_pool(),
::google::protobuf::MessageFactory::generated_factory(),
sizeof(RequestSystemExternalAccess));
ResponseSystemExternalAccess_descriptor_ = file->message_type(5);
static const int ResponseSystemExternalAccess_offsets_[3] = {
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ResponseSystemExternalAccess, status_),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ResponseSystemExternalAccess, ext_port_),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ResponseSystemExternalAccess, dht_key_),
};
ResponseSystemExternalAccess_reflection_ =
new ::google::protobuf::internal::GeneratedMessageReflection(
ResponseSystemExternalAccess_descriptor_,
ResponseSystemExternalAccess::default_instance_,
ResponseSystemExternalAccess_offsets_,
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ResponseSystemExternalAccess, _has_bits_[0]),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ResponseSystemExternalAccess, _unknown_fields_),
-1,
::google::protobuf::DescriptorPool::generated_pool(),
::google::protobuf::MessageFactory::generated_factory(),
sizeof(ResponseSystemExternalAccess));
RequestMsgIds_descriptor_ = file->enum_type(0);
ResponseMsgIds_descriptor_ = file->enum_type(1);
}
@ -131,6 +168,10 @@ void protobuf_RegisterTypes(const ::std::string&) {
RequestSystemQuit_descriptor_, &RequestSystemQuit::default_instance());
::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
ResponseSystemQuit_descriptor_, &ResponseSystemQuit::default_instance());
::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
RequestSystemExternalAccess_descriptor_, &RequestSystemExternalAccess::default_instance());
::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
ResponseSystemExternalAccess_descriptor_, &ResponseSystemExternalAccess::default_instance());
}
} // namespace
@ -144,6 +185,10 @@ void protobuf_ShutdownFile_system_2eproto() {
delete RequestSystemQuit_reflection_;
delete ResponseSystemQuit::default_instance_;
delete ResponseSystemQuit_reflection_;
delete RequestSystemExternalAccess::default_instance_;
delete RequestSystemExternalAccess_reflection_;
delete ResponseSystemExternalAccess::default_instance_;
delete ResponseSystemExternalAccess_reflection_;
}
void protobuf_AddDesc_system_2eproto() {
@ -169,21 +214,31 @@ void protobuf_AddDesc_system_2eproto() {
"(\0162).rsctrl.system.RequestSystemQuit.Qui"
"tCode\".\n\010QuitCode\022\021\n\rCLOSE_CHANNEL\020\001\022\017\n\013"
"SHUTDOWN_RS\020\002\"9\n\022ResponseSystemQuit\022#\n\006s"
"tatus\030\001 \002(\0132\023.rsctrl.core.Status*K\n\rRequ"
"estMsgIds\022\035\n\031MsgId_RequestSystemStatus\020\001"
"\022\033\n\027MsgId_RequestSystemQuit\020\002*N\n\016Respons"
"eMsgIds\022\036\n\032MsgId_ResponseSystemStatus\020\001\022"
"\034\n\030MsgId_ResponseSystemQuit\020\002", 789);
"tatus\030\001 \002(\0132\023.rsctrl.core.Status\"\035\n\033Requ"
"estSystemExternalAccess\"f\n\034ResponseSyste"
"mExternalAccess\022#\n\006status\030\001 \002(\0132\023.rsctrl"
".core.Status\022\020\n\010ext_port\030\002 \002(\r\022\017\n\007dht_ke"
"y\030\003 \002(\t*r\n\rRequestMsgIds\022\035\n\031MsgId_Reques"
"tSystemStatus\020\001\022\033\n\027MsgId_RequestSystemQu"
"it\020\002\022%\n!MsgId_RequestSystemExternalAcces"
"s\020\003*v\n\016ResponseMsgIds\022\036\n\032MsgId_ResponseS"
"ystemStatus\020\001\022\034\n\030MsgId_ResponseSystemQui"
"t\020\002\022&\n\"MsgId_ResponseSystemExternalAcces"
"s\020\003", 1003);
::google::protobuf::MessageFactory::InternalRegisterGeneratedFile(
"system.proto", &protobuf_RegisterTypes);
RequestSystemStatus::default_instance_ = new RequestSystemStatus();
ResponseSystemStatus::default_instance_ = new ResponseSystemStatus();
RequestSystemQuit::default_instance_ = new RequestSystemQuit();
ResponseSystemQuit::default_instance_ = new ResponseSystemQuit();
RequestSystemExternalAccess::default_instance_ = new RequestSystemExternalAccess();
ResponseSystemExternalAccess::default_instance_ = new ResponseSystemExternalAccess();
RequestSystemStatus::default_instance_->InitAsDefaultInstance();
ResponseSystemStatus::default_instance_->InitAsDefaultInstance();
RequestSystemQuit::default_instance_->InitAsDefaultInstance();
ResponseSystemQuit::default_instance_->InitAsDefaultInstance();
RequestSystemExternalAccess::default_instance_->InitAsDefaultInstance();
ResponseSystemExternalAccess::default_instance_->InitAsDefaultInstance();
::google::protobuf::internal::OnShutdown(&protobuf_ShutdownFile_system_2eproto);
}
@ -202,6 +257,7 @@ bool RequestMsgIds_IsValid(int value) {
switch(value) {
case 1:
case 2:
case 3:
return true;
default:
return false;
@ -216,6 +272,7 @@ bool ResponseMsgIds_IsValid(int value) {
switch(value) {
case 1:
case 2:
case 3:
return true;
default:
return false;
@ -1254,6 +1311,474 @@ void ResponseSystemQuit::Swap(ResponseSystemQuit* other) {
}
// ===================================================================
#ifndef _MSC_VER
#endif // !_MSC_VER
RequestSystemExternalAccess::RequestSystemExternalAccess()
: ::google::protobuf::Message() {
SharedCtor();
}
void RequestSystemExternalAccess::InitAsDefaultInstance() {
}
RequestSystemExternalAccess::RequestSystemExternalAccess(const RequestSystemExternalAccess& from)
: ::google::protobuf::Message() {
SharedCtor();
MergeFrom(from);
}
void RequestSystemExternalAccess::SharedCtor() {
_cached_size_ = 0;
::memset(_has_bits_, 0, sizeof(_has_bits_));
}
RequestSystemExternalAccess::~RequestSystemExternalAccess() {
SharedDtor();
}
void RequestSystemExternalAccess::SharedDtor() {
if (this != default_instance_) {
}
}
void RequestSystemExternalAccess::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
_cached_size_ = size;
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* RequestSystemExternalAccess::descriptor() {
protobuf_AssignDescriptorsOnce();
return RequestSystemExternalAccess_descriptor_;
}
const RequestSystemExternalAccess& RequestSystemExternalAccess::default_instance() {
if (default_instance_ == NULL) protobuf_AddDesc_system_2eproto(); return *default_instance_;
}
RequestSystemExternalAccess* RequestSystemExternalAccess::default_instance_ = NULL;
RequestSystemExternalAccess* RequestSystemExternalAccess::New() const {
return new RequestSystemExternalAccess;
}
void RequestSystemExternalAccess::Clear() {
::memset(_has_bits_, 0, sizeof(_has_bits_));
mutable_unknown_fields()->Clear();
}
bool RequestSystemExternalAccess::MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input) {
#define DO_(EXPRESSION) if (!(EXPRESSION)) return false
::google::protobuf::uint32 tag;
while ((tag = input->ReadTag()) != 0) {
if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) {
return true;
}
DO_(::google::protobuf::internal::WireFormat::SkipField(
input, tag, mutable_unknown_fields()));
}
return true;
#undef DO_
}
void RequestSystemExternalAccess::SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const {
if (!unknown_fields().empty()) {
::google::protobuf::internal::WireFormat::SerializeUnknownFields(
unknown_fields(), output);
}
}
::google::protobuf::uint8* RequestSystemExternalAccess::SerializeWithCachedSizesToArray(
::google::protobuf::uint8* target) const {
if (!unknown_fields().empty()) {
target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(
unknown_fields(), target);
}
return target;
}
int RequestSystemExternalAccess::ByteSize() const {
int total_size = 0;
if (!unknown_fields().empty()) {
total_size +=
::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
unknown_fields());
}
GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
_cached_size_ = total_size;
GOOGLE_SAFE_CONCURRENT_WRITES_END();
return total_size;
}
void RequestSystemExternalAccess::MergeFrom(const ::google::protobuf::Message& from) {
GOOGLE_CHECK_NE(&from, this);
const RequestSystemExternalAccess* source =
::google::protobuf::internal::dynamic_cast_if_available<const RequestSystemExternalAccess*>(
&from);
if (source == NULL) {
::google::protobuf::internal::ReflectionOps::Merge(from, this);
} else {
MergeFrom(*source);
}
}
void RequestSystemExternalAccess::MergeFrom(const RequestSystemExternalAccess& from) {
GOOGLE_CHECK_NE(&from, this);
mutable_unknown_fields()->MergeFrom(from.unknown_fields());
}
void RequestSystemExternalAccess::CopyFrom(const ::google::protobuf::Message& from) {
if (&from == this) return;
Clear();
MergeFrom(from);
}
void RequestSystemExternalAccess::CopyFrom(const RequestSystemExternalAccess& from) {
if (&from == this) return;
Clear();
MergeFrom(from);
}
bool RequestSystemExternalAccess::IsInitialized() const {
return true;
}
void RequestSystemExternalAccess::Swap(RequestSystemExternalAccess* other) {
if (other != this) {
_unknown_fields_.Swap(&other->_unknown_fields_);
std::swap(_cached_size_, other->_cached_size_);
}
}
::google::protobuf::Metadata RequestSystemExternalAccess::GetMetadata() const {
protobuf_AssignDescriptorsOnce();
::google::protobuf::Metadata metadata;
metadata.descriptor = RequestSystemExternalAccess_descriptor_;
metadata.reflection = RequestSystemExternalAccess_reflection_;
return metadata;
}
// ===================================================================
#ifndef _MSC_VER
const int ResponseSystemExternalAccess::kStatusFieldNumber;
const int ResponseSystemExternalAccess::kExtPortFieldNumber;
const int ResponseSystemExternalAccess::kDhtKeyFieldNumber;
#endif // !_MSC_VER
ResponseSystemExternalAccess::ResponseSystemExternalAccess()
: ::google::protobuf::Message() {
SharedCtor();
}
void ResponseSystemExternalAccess::InitAsDefaultInstance() {
status_ = const_cast< ::rsctrl::core::Status*>(&::rsctrl::core::Status::default_instance());
}
ResponseSystemExternalAccess::ResponseSystemExternalAccess(const ResponseSystemExternalAccess& from)
: ::google::protobuf::Message() {
SharedCtor();
MergeFrom(from);
}
void ResponseSystemExternalAccess::SharedCtor() {
_cached_size_ = 0;
status_ = NULL;
ext_port_ = 0u;
dht_key_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString);
::memset(_has_bits_, 0, sizeof(_has_bits_));
}
ResponseSystemExternalAccess::~ResponseSystemExternalAccess() {
SharedDtor();
}
void ResponseSystemExternalAccess::SharedDtor() {
if (dht_key_ != &::google::protobuf::internal::kEmptyString) {
delete dht_key_;
}
if (this != default_instance_) {
delete status_;
}
}
void ResponseSystemExternalAccess::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
_cached_size_ = size;
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* ResponseSystemExternalAccess::descriptor() {
protobuf_AssignDescriptorsOnce();
return ResponseSystemExternalAccess_descriptor_;
}
const ResponseSystemExternalAccess& ResponseSystemExternalAccess::default_instance() {
if (default_instance_ == NULL) protobuf_AddDesc_system_2eproto(); return *default_instance_;
}
ResponseSystemExternalAccess* ResponseSystemExternalAccess::default_instance_ = NULL;
ResponseSystemExternalAccess* ResponseSystemExternalAccess::New() const {
return new ResponseSystemExternalAccess;
}
void ResponseSystemExternalAccess::Clear() {
if (_has_bits_[0 / 32] & (0xffu << (0 % 32))) {
if (has_status()) {
if (status_ != NULL) status_->::rsctrl::core::Status::Clear();
}
ext_port_ = 0u;
if (has_dht_key()) {
if (dht_key_ != &::google::protobuf::internal::kEmptyString) {
dht_key_->clear();
}
}
}
::memset(_has_bits_, 0, sizeof(_has_bits_));
mutable_unknown_fields()->Clear();
}
bool ResponseSystemExternalAccess::MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input) {
#define DO_(EXPRESSION) if (!(EXPRESSION)) return false
::google::protobuf::uint32 tag;
while ((tag = input->ReadTag()) != 0) {
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
// required .rsctrl.core.Status status = 1;
case 1: {
if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED) {
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual(
input, mutable_status()));
} else {
goto handle_uninterpreted;
}
if (input->ExpectTag(16)) goto parse_ext_port;
break;
}
// required uint32 ext_port = 2;
case 2: {
if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
::google::protobuf::internal::WireFormatLite::WIRETYPE_VARINT) {
parse_ext_port:
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
::google::protobuf::uint32, ::google::protobuf::internal::WireFormatLite::TYPE_UINT32>(
input, &ext_port_)));
set_has_ext_port();
} else {
goto handle_uninterpreted;
}
if (input->ExpectTag(26)) goto parse_dht_key;
break;
}
// required string dht_key = 3;
case 3: {
if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED) {
parse_dht_key:
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_dht_key()));
::google::protobuf::internal::WireFormat::VerifyUTF8String(
this->dht_key().data(), this->dht_key().length(),
::google::protobuf::internal::WireFormat::PARSE);
} else {
goto handle_uninterpreted;
}
if (input->ExpectAtEnd()) return true;
break;
}
default: {
handle_uninterpreted:
if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) {
return true;
}
DO_(::google::protobuf::internal::WireFormat::SkipField(
input, tag, mutable_unknown_fields()));
break;
}
}
}
return true;
#undef DO_
}
void ResponseSystemExternalAccess::SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const {
// required .rsctrl.core.Status status = 1;
if (has_status()) {
::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray(
1, this->status(), output);
}
// required uint32 ext_port = 2;
if (has_ext_port()) {
::google::protobuf::internal::WireFormatLite::WriteUInt32(2, this->ext_port(), output);
}
// required string dht_key = 3;
if (has_dht_key()) {
::google::protobuf::internal::WireFormat::VerifyUTF8String(
this->dht_key().data(), this->dht_key().length(),
::google::protobuf::internal::WireFormat::SERIALIZE);
::google::protobuf::internal::WireFormatLite::WriteString(
3, this->dht_key(), output);
}
if (!unknown_fields().empty()) {
::google::protobuf::internal::WireFormat::SerializeUnknownFields(
unknown_fields(), output);
}
}
::google::protobuf::uint8* ResponseSystemExternalAccess::SerializeWithCachedSizesToArray(
::google::protobuf::uint8* target) const {
// required .rsctrl.core.Status status = 1;
if (has_status()) {
target = ::google::protobuf::internal::WireFormatLite::
WriteMessageNoVirtualToArray(
1, this->status(), target);
}
// required uint32 ext_port = 2;
if (has_ext_port()) {
target = ::google::protobuf::internal::WireFormatLite::WriteUInt32ToArray(2, this->ext_port(), target);
}
// required string dht_key = 3;
if (has_dht_key()) {
::google::protobuf::internal::WireFormat::VerifyUTF8String(
this->dht_key().data(), this->dht_key().length(),
::google::protobuf::internal::WireFormat::SERIALIZE);
target =
::google::protobuf::internal::WireFormatLite::WriteStringToArray(
3, this->dht_key(), target);
}
if (!unknown_fields().empty()) {
target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(
unknown_fields(), target);
}
return target;
}
int ResponseSystemExternalAccess::ByteSize() const {
int total_size = 0;
if (_has_bits_[0 / 32] & (0xffu << (0 % 32))) {
// required .rsctrl.core.Status status = 1;
if (has_status()) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual(
this->status());
}
// required uint32 ext_port = 2;
if (has_ext_port()) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::UInt32Size(
this->ext_port());
}
// required string dht_key = 3;
if (has_dht_key()) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::StringSize(
this->dht_key());
}
}
if (!unknown_fields().empty()) {
total_size +=
::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
unknown_fields());
}
GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
_cached_size_ = total_size;
GOOGLE_SAFE_CONCURRENT_WRITES_END();
return total_size;
}
void ResponseSystemExternalAccess::MergeFrom(const ::google::protobuf::Message& from) {
GOOGLE_CHECK_NE(&from, this);
const ResponseSystemExternalAccess* source =
::google::protobuf::internal::dynamic_cast_if_available<const ResponseSystemExternalAccess*>(
&from);
if (source == NULL) {
::google::protobuf::internal::ReflectionOps::Merge(from, this);
} else {
MergeFrom(*source);
}
}
void ResponseSystemExternalAccess::MergeFrom(const ResponseSystemExternalAccess& from) {
GOOGLE_CHECK_NE(&from, this);
if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) {
if (from.has_status()) {
mutable_status()->::rsctrl::core::Status::MergeFrom(from.status());
}
if (from.has_ext_port()) {
set_ext_port(from.ext_port());
}
if (from.has_dht_key()) {
set_dht_key(from.dht_key());
}
}
mutable_unknown_fields()->MergeFrom(from.unknown_fields());
}
void ResponseSystemExternalAccess::CopyFrom(const ::google::protobuf::Message& from) {
if (&from == this) return;
Clear();
MergeFrom(from);
}
void ResponseSystemExternalAccess::CopyFrom(const ResponseSystemExternalAccess& from) {
if (&from == this) return;
Clear();
MergeFrom(from);
}
bool ResponseSystemExternalAccess::IsInitialized() const {
if ((_has_bits_[0] & 0x00000007) != 0x00000007) return false;
if (has_status()) {
if (!this->status().IsInitialized()) return false;
}
return true;
}
void ResponseSystemExternalAccess::Swap(ResponseSystemExternalAccess* other) {
if (other != this) {
std::swap(status_, other->status_);
std::swap(ext_port_, other->ext_port_);
std::swap(dht_key_, other->dht_key_);
std::swap(_has_bits_[0], other->_has_bits_[0]);
_unknown_fields_.Swap(&other->_unknown_fields_);
std::swap(_cached_size_, other->_cached_size_);
}
}
::google::protobuf::Metadata ResponseSystemExternalAccess::GetMetadata() const {
protobuf_AssignDescriptorsOnce();
::google::protobuf::Metadata metadata;
metadata.descriptor = ResponseSystemExternalAccess_descriptor_;
metadata.reflection = ResponseSystemExternalAccess_reflection_;
return metadata;
}
// @@protoc_insertion_point(namespace_scope)
} // namespace system

View File

@ -38,6 +38,8 @@ class RequestSystemStatus;
class ResponseSystemStatus;
class RequestSystemQuit;
class ResponseSystemQuit;
class RequestSystemExternalAccess;
class ResponseSystemExternalAccess;
enum ResponseSystemStatus_NetCode {
ResponseSystemStatus_NetCode_BAD_UNKNOWN = 0,
@ -86,11 +88,12 @@ inline bool RequestSystemQuit_QuitCode_Parse(
}
enum RequestMsgIds {
MsgId_RequestSystemStatus = 1,
MsgId_RequestSystemQuit = 2
MsgId_RequestSystemQuit = 2,
MsgId_RequestSystemExternalAccess = 3
};
bool RequestMsgIds_IsValid(int value);
const RequestMsgIds RequestMsgIds_MIN = MsgId_RequestSystemStatus;
const RequestMsgIds RequestMsgIds_MAX = MsgId_RequestSystemQuit;
const RequestMsgIds RequestMsgIds_MAX = MsgId_RequestSystemExternalAccess;
const int RequestMsgIds_ARRAYSIZE = RequestMsgIds_MAX + 1;
const ::google::protobuf::EnumDescriptor* RequestMsgIds_descriptor();
@ -105,11 +108,12 @@ inline bool RequestMsgIds_Parse(
}
enum ResponseMsgIds {
MsgId_ResponseSystemStatus = 1,
MsgId_ResponseSystemQuit = 2
MsgId_ResponseSystemQuit = 2,
MsgId_ResponseSystemExternalAccess = 3
};
bool ResponseMsgIds_IsValid(int value);
const ResponseMsgIds ResponseMsgIds_MIN = MsgId_ResponseSystemStatus;
const ResponseMsgIds ResponseMsgIds_MAX = MsgId_ResponseSystemQuit;
const ResponseMsgIds ResponseMsgIds_MAX = MsgId_ResponseSystemExternalAccess;
const int ResponseMsgIds_ARRAYSIZE = ResponseMsgIds_MAX + 1;
const ::google::protobuf::EnumDescriptor* ResponseMsgIds_descriptor();
@ -538,6 +542,185 @@ class ResponseSystemQuit : public ::google::protobuf::Message {
void InitAsDefaultInstance();
static ResponseSystemQuit* default_instance_;
};
// -------------------------------------------------------------------
class RequestSystemExternalAccess : public ::google::protobuf::Message {
public:
RequestSystemExternalAccess();
virtual ~RequestSystemExternalAccess();
RequestSystemExternalAccess(const RequestSystemExternalAccess& from);
inline RequestSystemExternalAccess& operator=(const RequestSystemExternalAccess& from) {
CopyFrom(from);
return *this;
}
inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
return _unknown_fields_;
}
inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
return &_unknown_fields_;
}
static const ::google::protobuf::Descriptor* descriptor();
static const RequestSystemExternalAccess& default_instance();
void Swap(RequestSystemExternalAccess* other);
// implements Message ----------------------------------------------
RequestSystemExternalAccess* New() const;
void CopyFrom(const ::google::protobuf::Message& from);
void MergeFrom(const ::google::protobuf::Message& from);
void CopyFrom(const RequestSystemExternalAccess& from);
void MergeFrom(const RequestSystemExternalAccess& from);
void Clear();
bool IsInitialized() const;
int ByteSize() const;
bool MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input);
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
int GetCachedSize() const { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
void SetCachedSize(int size) const;
public:
::google::protobuf::Metadata GetMetadata() const;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
// @@protoc_insertion_point(class_scope:rsctrl.system.RequestSystemExternalAccess)
private:
::google::protobuf::UnknownFieldSet _unknown_fields_;
mutable int _cached_size_;
::google::protobuf::uint32 _has_bits_[1];
friend void protobuf_AddDesc_system_2eproto();
friend void protobuf_AssignDesc_system_2eproto();
friend void protobuf_ShutdownFile_system_2eproto();
void InitAsDefaultInstance();
static RequestSystemExternalAccess* default_instance_;
};
// -------------------------------------------------------------------
class ResponseSystemExternalAccess : public ::google::protobuf::Message {
public:
ResponseSystemExternalAccess();
virtual ~ResponseSystemExternalAccess();
ResponseSystemExternalAccess(const ResponseSystemExternalAccess& from);
inline ResponseSystemExternalAccess& operator=(const ResponseSystemExternalAccess& from) {
CopyFrom(from);
return *this;
}
inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
return _unknown_fields_;
}
inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
return &_unknown_fields_;
}
static const ::google::protobuf::Descriptor* descriptor();
static const ResponseSystemExternalAccess& default_instance();
void Swap(ResponseSystemExternalAccess* other);
// implements Message ----------------------------------------------
ResponseSystemExternalAccess* New() const;
void CopyFrom(const ::google::protobuf::Message& from);
void MergeFrom(const ::google::protobuf::Message& from);
void CopyFrom(const ResponseSystemExternalAccess& from);
void MergeFrom(const ResponseSystemExternalAccess& from);
void Clear();
bool IsInitialized() const;
int ByteSize() const;
bool MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input);
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
int GetCachedSize() const { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
void SetCachedSize(int size) const;
public:
::google::protobuf::Metadata GetMetadata() const;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
// required .rsctrl.core.Status status = 1;
inline bool has_status() const;
inline void clear_status();
static const int kStatusFieldNumber = 1;
inline const ::rsctrl::core::Status& status() const;
inline ::rsctrl::core::Status* mutable_status();
inline ::rsctrl::core::Status* release_status();
// required uint32 ext_port = 2;
inline bool has_ext_port() const;
inline void clear_ext_port();
static const int kExtPortFieldNumber = 2;
inline ::google::protobuf::uint32 ext_port() const;
inline void set_ext_port(::google::protobuf::uint32 value);
// required string dht_key = 3;
inline bool has_dht_key() const;
inline void clear_dht_key();
static const int kDhtKeyFieldNumber = 3;
inline const ::std::string& dht_key() const;
inline void set_dht_key(const ::std::string& value);
inline void set_dht_key(const char* value);
inline void set_dht_key(const char* value, size_t size);
inline ::std::string* mutable_dht_key();
inline ::std::string* release_dht_key();
// @@protoc_insertion_point(class_scope:rsctrl.system.ResponseSystemExternalAccess)
private:
inline void set_has_status();
inline void clear_has_status();
inline void set_has_ext_port();
inline void clear_has_ext_port();
inline void set_has_dht_key();
inline void clear_has_dht_key();
::google::protobuf::UnknownFieldSet _unknown_fields_;
::rsctrl::core::Status* status_;
::std::string* dht_key_;
::google::protobuf::uint32 ext_port_;
mutable int _cached_size_;
::google::protobuf::uint32 _has_bits_[(3 + 31) / 32];
friend void protobuf_AddDesc_system_2eproto();
friend void protobuf_AssignDesc_system_2eproto();
friend void protobuf_ShutdownFile_system_2eproto();
void InitAsDefaultInstance();
static ResponseSystemExternalAccess* default_instance_;
};
// ===================================================================
@ -734,6 +917,123 @@ inline ::rsctrl::core::Status* ResponseSystemQuit::release_status() {
return temp;
}
// -------------------------------------------------------------------
// RequestSystemExternalAccess
// -------------------------------------------------------------------
// ResponseSystemExternalAccess
// required .rsctrl.core.Status status = 1;
inline bool ResponseSystemExternalAccess::has_status() const {
return (_has_bits_[0] & 0x00000001u) != 0;
}
inline void ResponseSystemExternalAccess::set_has_status() {
_has_bits_[0] |= 0x00000001u;
}
inline void ResponseSystemExternalAccess::clear_has_status() {
_has_bits_[0] &= ~0x00000001u;
}
inline void ResponseSystemExternalAccess::clear_status() {
if (status_ != NULL) status_->::rsctrl::core::Status::Clear();
clear_has_status();
}
inline const ::rsctrl::core::Status& ResponseSystemExternalAccess::status() const {
return status_ != NULL ? *status_ : *default_instance_->status_;
}
inline ::rsctrl::core::Status* ResponseSystemExternalAccess::mutable_status() {
set_has_status();
if (status_ == NULL) status_ = new ::rsctrl::core::Status;
return status_;
}
inline ::rsctrl::core::Status* ResponseSystemExternalAccess::release_status() {
clear_has_status();
::rsctrl::core::Status* temp = status_;
status_ = NULL;
return temp;
}
// required uint32 ext_port = 2;
inline bool ResponseSystemExternalAccess::has_ext_port() const {
return (_has_bits_[0] & 0x00000002u) != 0;
}
inline void ResponseSystemExternalAccess::set_has_ext_port() {
_has_bits_[0] |= 0x00000002u;
}
inline void ResponseSystemExternalAccess::clear_has_ext_port() {
_has_bits_[0] &= ~0x00000002u;
}
inline void ResponseSystemExternalAccess::clear_ext_port() {
ext_port_ = 0u;
clear_has_ext_port();
}
inline ::google::protobuf::uint32 ResponseSystemExternalAccess::ext_port() const {
return ext_port_;
}
inline void ResponseSystemExternalAccess::set_ext_port(::google::protobuf::uint32 value) {
set_has_ext_port();
ext_port_ = value;
}
// required string dht_key = 3;
inline bool ResponseSystemExternalAccess::has_dht_key() const {
return (_has_bits_[0] & 0x00000004u) != 0;
}
inline void ResponseSystemExternalAccess::set_has_dht_key() {
_has_bits_[0] |= 0x00000004u;
}
inline void ResponseSystemExternalAccess::clear_has_dht_key() {
_has_bits_[0] &= ~0x00000004u;
}
inline void ResponseSystemExternalAccess::clear_dht_key() {
if (dht_key_ != &::google::protobuf::internal::kEmptyString) {
dht_key_->clear();
}
clear_has_dht_key();
}
inline const ::std::string& ResponseSystemExternalAccess::dht_key() const {
return *dht_key_;
}
inline void ResponseSystemExternalAccess::set_dht_key(const ::std::string& value) {
set_has_dht_key();
if (dht_key_ == &::google::protobuf::internal::kEmptyString) {
dht_key_ = new ::std::string;
}
dht_key_->assign(value);
}
inline void ResponseSystemExternalAccess::set_dht_key(const char* value) {
set_has_dht_key();
if (dht_key_ == &::google::protobuf::internal::kEmptyString) {
dht_key_ = new ::std::string;
}
dht_key_->assign(value);
}
inline void ResponseSystemExternalAccess::set_dht_key(const char* value, size_t size) {
set_has_dht_key();
if (dht_key_ == &::google::protobuf::internal::kEmptyString) {
dht_key_ = new ::std::string;
}
dht_key_->assign(reinterpret_cast<const char*>(value), size);
}
inline ::std::string* ResponseSystemExternalAccess::mutable_dht_key() {
set_has_dht_key();
if (dht_key_ == &::google::protobuf::internal::kEmptyString) {
dht_key_ = new ::std::string;
}
return dht_key_;
}
inline ::std::string* ResponseSystemExternalAccess::release_dht_key() {
clear_has_dht_key();
if (dht_key_ == &::google::protobuf::internal::kEmptyString) {
return NULL;
} else {
::std::string* temp = dht_key_;
dht_key_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString);
return temp;
}
}
// @@protoc_insertion_point(namespace_scope)

View File

@ -27,10 +27,14 @@
#include <retroshare/rspeers.h>
#include <retroshare/rsconfig.h>
#include <retroshare/rsiface.h>
#include <retroshare/rsdht.h>
#include <iostream>
#include <algorithm>
// NASTY GLOBAL VARIABLE HACK - NEED TO THINK OF A BETTER SYSTEM.
uint16_t RpcProtoSystem::mExtPort = 0;
RpcProtoSystem::RpcProtoSystem(uint32_t serviceId)
:RpcQueueService(serviceId)
{
@ -91,6 +95,9 @@ int RpcProtoSystem::processMsg(uint32_t chan_id, uint32_t msg_id, uint32_t req_i
processSystemQuit(chan_id, msg_id, req_id, msg);
break;
#endif
case rsctrl::system::MsgId_RequestSystemExternalAccess:
processSystemExternalAccess(chan_id, msg_id, req_id, msg);
break;
default:
std::cerr << "RpcProtoSystem::processMsg() ERROR should never get here";
std::cerr << std::endl;
@ -284,3 +291,64 @@ int RpcProtoSystem::processSystemQuit(uint32_t chan_id, uint32_t msg_id, uint32_
}
int RpcProtoSystem::processSystemExternalAccess(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg)
{
std::cerr << "RpcProtoSystem::processSystemExternalAccess()";
std::cerr << std::endl;
// parse msg.
rsctrl::system::RequestSystemExternalAccess req;
if (!req.ParseFromString(msg))
{
std::cerr << "RpcProtoSystem::processSystemExternalAccess() ERROR ParseFromString()";
std::cerr << std::endl;
return 0;
}
// NO Options... so go straight to answer.
// response.
rsctrl::system::ResponseSystemExternalAccess resp;
bool success = true;
std::string dhtKey;
if (!rsDht->getOwnDhtId(dhtKey))
{
success = false;
}
// have to set something anyway!.
resp.set_dht_key(dhtKey);
// NASTY GLOBAL VARIABLE HACK - NEED TO THINK OF A BETTER SYSTEM.
resp.set_ext_port(mExtPort);
if (success)
{
rsctrl::core::Status *status = resp.mutable_status();
status->set_code(rsctrl::core::Status::SUCCESS);
}
else
{
rsctrl::core::Status *status = resp.mutable_status();
status->set_code(rsctrl::core::Status::FAILED);
status->set_msg("Unknown ERROR");
}
std::string outmsg;
if (!resp.SerializeToString(&outmsg))
{
std::cerr << "RpcProtoSystem::processSystemExternalAccess() ERROR SerialiseToString()";
std::cerr << std::endl;
return 0;
}
// Correctly Name Message.
uint32_t out_msg_id = constructMsgId(rsctrl::core::CORE, rsctrl::core::SYSTEM,
rsctrl::system::MsgId_ResponseSystemExternalAccess, true);
// queue it.
queueResponse(chan_id, out_msg_id, req_id, outmsg);
return 1;
}

View File

@ -36,6 +36,11 @@ public:
virtual int processSystemStatus(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg);
virtual int processSystemQuit(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg);
virtual int processSystemExternalAccess(uint32_t chan_id, uint32_t msg_id, uint32_t req_id, const std::string &msg);
// NASTY GLOBAL VARIABLE HACK - NEED TO THINK OF A BETTER SYSTEM.
static uint16_t mExtPort;
};

View File

@ -9,11 +9,13 @@ import "core.proto";
enum RequestMsgIds {
MsgId_RequestSystemStatus = 1;
MsgId_RequestSystemQuit = 2;
MsgId_RequestSystemExternalAccess = 3;
}
enum ResponseMsgIds {
MsgId_ResponseSystemStatus = 1;
MsgId_ResponseSystemQuit = 2;
MsgId_ResponseSystemExternalAccess = 3;
}
///////////////////////////////////////////////////////////////
@ -73,6 +75,24 @@ message ResponseSystemQuit {
required rsctrl.core.Status status = 1;
}
///////////////////////////////////////////////////////////////
// REQUEST: RequestSystemExternalAccess
message RequestSystemExternalAccess {
// Nothing here?
}
// RESPONSE: ResponseSystemExternalAccess
message ResponseSystemExternalAccess {
// Status of response.
required rsctrl.core.Status status = 1;
required uint32 ext_port = 2;
required string dht_key = 3;
}
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////