From 6ca49a2d98ccdd59af76d9f778a9113d2b449ee0 Mon Sep 17 00:00:00 2001 From: csoler Date: Fri, 27 Nov 2015 23:37:39 -0500 Subject: [PATCH] fixed serialisation methods for GxsTunnel service --- libretroshare/src/chat/rschatitems.cc | 81 - libretroshare/src/gxstunnel/p3gxstunnel.cc | 2 +- .../src/gxstunnel/rsgxstunnelitems.cc | 1416 ++++------------- .../src/gxstunnel/rsgxstunnelitems.h | 33 +- libretroshare/src/retroshare/rsgxstunnel.h | 6 +- libretroshare/src/rsserver/p3face.h | 2 + libretroshare/src/rsserver/rsinit.cc | 6 +- 7 files changed, 298 insertions(+), 1248 deletions(-) diff --git a/libretroshare/src/chat/rschatitems.cc b/libretroshare/src/chat/rschatitems.cc index e44102bc4..1074eee1c 100644 --- a/libretroshare/src/chat/rschatitems.cc +++ b/libretroshare/src/chat/rschatitems.cc @@ -51,18 +51,6 @@ std::ostream& RsChatMsgItem::print(std::ostream &out, uint16_t indent) printRsItemEnd(out, "RsChatMsgItem", indent); return out; } -std::ostream& RsChatDHPublicKeyItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsChatDHPublicKeyItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << " Signature Key ID: " << signature.keyId << std::endl ; - out << " Public Key ID: " << gxs_key.keyId << std::endl ; - - printRsItemEnd(out, "RsChatMsgItem", indent); - return out; -} std::ostream& RsChatLobbyListItem::print(std::ostream &out, uint16_t indent) { @@ -277,7 +265,6 @@ RsItem *RsChatSerialiser::deserialise(void *data, uint32_t *pktsize) case RS_PKT_SUBTYPE_CHAT_LOBBY_LIST_REQUEST: return new RsChatLobbyListRequestItem(data,*pktsize) ; case RS_PKT_SUBTYPE_CHAT_LOBBY_LIST: return new RsChatLobbyListItem(data,*pktsize) ; case RS_PKT_SUBTYPE_CHAT_LOBBY_CONFIG: return new RsChatLobbyConfigItem(data,*pktsize) ; - case RS_PKT_SUBTYPE_DISTANT_CHAT_DH_PUBLIC_KEY: return new RsChatDHPublicKeyItem(data,*pktsize) ; default: std::cerr << "Unknown packet type in chat!" << std::endl ; return NULL ; @@ -437,17 +424,6 @@ uint32_t RsChatLobbyConfigItem::serial_size() return s; } -uint32_t RsChatDHPublicKeyItem::serial_size() -{ - uint32_t s = 8 ; // header - s += 4 ; // BN size - s += BN_num_bytes(public_key) ; // public_key - s += signature.TlvSize() ; // signature - s += gxs_key.TlvSize() ; // gxs_key - - return s ; -} - /*************************************************************************/ RsChatAvatarItem::~RsChatAvatarItem() @@ -459,41 +435,6 @@ RsChatAvatarItem::~RsChatAvatarItem() } } -bool RsChatDHPublicKeyItem::serialise(void *data,uint32_t& pktsize) -{ - uint32_t tlvsize = serial_size() ; - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); - - /* skip the header */ - offset += 8; - - uint32_t s = BN_num_bytes(public_key) ; - - ok &= setRawUInt32(data, tlvsize, &offset, s); - - BN_bn2bin(public_key,&((unsigned char *)data)[offset]) ; - offset += s ; - - ok &= signature.SetTlv(data, tlvsize, &offset); - ok &= gxs_key.SetTlv(data, tlvsize, &offset); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsChatDHPublicKeyItem::serialiseItem() Size Error! offset=" << offset << ", tlvsize=" << tlvsize << std::endl; - } - return ok ; -} - /* serialise the data to the buffer */ bool RsChatMsgItem::serialise(void *data, uint32_t& pktsize) { @@ -995,28 +936,6 @@ bool RsChatLobbyConfigItem::serialise(void *data, uint32_t& pktsize) return ok; } -RsChatDHPublicKeyItem::RsChatDHPublicKeyItem(void *data,uint32_t /*size*/) - : RsChatItem(RS_PKT_SUBTYPE_DISTANT_CHAT_DH_PUBLIC_KEY) -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - - uint32_t s=0 ; - /* get mandatory parts first */ - ok &= getRawUInt32(data, rssize, &offset, &s); - - public_key = BN_bin2bn(&((unsigned char *)data)[offset],s,NULL) ; - offset += s ; - - ok &= signature.GetTlv(data, rssize, &offset) ; - ok &= gxs_key.GetTlv(data, rssize, &offset) ; - - if (offset != rssize) - std::cerr << "RsChatDHPublicKeyItem::() Size error while deserializing." << std::endl ; - if (!ok) - std::cerr << "RsChatDHPublicKeyItem::() Unknown error while deserializing." << std::endl ; -} RsChatMsgItem::RsChatMsgItem(void *data,uint32_t /*size*/,uint8_t subtype) : RsChatItem(subtype) { diff --git a/libretroshare/src/gxstunnel/p3gxstunnel.cc b/libretroshare/src/gxstunnel/p3gxstunnel.cc index b2c1fffae..831804fc9 100644 --- a/libretroshare/src/gxstunnel/p3gxstunnel.cc +++ b/libretroshare/src/gxstunnel/p3gxstunnel.cc @@ -585,7 +585,7 @@ bool p3GxsTunnelService::handleEncryptedData(const uint8_t *data_bytes,uint32_t // Now try deserialise the decrypted data to make an RsItem out of it. // - citem = RsGxsTunnelSerialiser().deserialiseGxsTunnelItem(decrypted_data,&decrypted_size) ; + citem = dynamic_cast(RsGxsTunnelSerialiser().deserialise(decrypted_data,&decrypted_size)) ; delete[] decrypted_data ; diff --git a/libretroshare/src/gxstunnel/rsgxstunnelitems.cc b/libretroshare/src/gxstunnel/rsgxstunnelitems.cc index e08421120..15522c000 100644 --- a/libretroshare/src/gxstunnel/rsgxstunnelitems.cc +++ b/libretroshare/src/gxstunnel/rsgxstunnelitems.cc @@ -28,423 +28,120 @@ #include #include "serialiser/rsbaseserial.h" #include "serialiser/rstlvbase.h" +#include "util/rsprint.h" -#include "chat/rschatitems.h" +#include "gxstunnel/rsgxstunnelitems.h" -//#define CHAT_DEBUG 1 +//#define GXS_TUNNEL_ITEM_DEBUG 1 -std::ostream& RsChatMsgItem::print(std::ostream &out, uint16_t indent) +std::ostream& RsGxsTunnelDHPublicKeyItem::print(std::ostream &out, uint16_t indent) { - printRsItemBase(out, "RsChatMsgItem", indent); + printRsItemBase(out, "RsGxsTunnelDHPublicKeyItem", indent); uint16_t int_Indent = indent + 2; - printIndent(out, int_Indent); - out << "QblogMs " << chatFlags << std::endl; - - printIndent(out, int_Indent); - out << "sendTime: " << sendTime << " (" << time(NULL)-sendTime << " secs ago)" << std::endl; - - printIndent(out, int_Indent); - - std::string cnv_message(message.begin(), message.end()); - out << "msg: " << cnv_message << std::endl; - - printRsItemEnd(out, "RsChatMsgItem", indent); - return out; -} -std::ostream& RsChatDHPublicKeyItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsChatDHPublicKeyItem", indent); - uint16_t int_Indent = indent + 2; printIndent(out, int_Indent); out << " Signature Key ID: " << signature.keyId << std::endl ; out << " Public Key ID: " << gxs_key.keyId << std::endl ; - printRsItemEnd(out, "RsChatMsgItem", indent); + printRsItemEnd(out, "RsGxsTunnelMsgItem", indent); return out; } -std::ostream& RsChatLobbyListItem::print(std::ostream &out, uint16_t indent) +std::ostream& RsGxsTunnelDataItem::print(std::ostream &out, uint16_t indent) { - printRsItemBase(out, "RsChatLobbyListItem", indent); - - for(uint32_t i=0;i50u)?"...":"") << std::endl ; - printIndent(out, int_Indent); - out << "lobby id: " << std::hex << lobby_id << std::dec << std::endl; - - printIndent(out, int_Indent); - out << "lobby name: " << lobby_name << std::endl; - - printIndent(out, int_Indent); - out << "lobby topic: " << lobby_topic << std::endl; - - printRsItemEnd(out, "RsChatLobbyInviteItem", indent); + printRsItemEnd(out, "RsGxsTunnelDataItem", indent); return out; } -std::ostream& RsPrivateChatMsgConfigItem::print(std::ostream &out, uint16_t indent) +std::ostream& RsGxsTunnelDataAckItem::print(std::ostream &out, uint16_t indent) { - printRsItemBase(out, "RsPrivateChatMsgConfigItem", indent); - uint16_t int_Indent = indent + 2; - - out << "peerId: " << configPeerId << std::endl; - - printIndent(out, int_Indent); - out << "QblogMs " << chatFlags << std::endl; - - printIndent(out, int_Indent); - out << "QblogMs " << configFlags << std::endl; - - printIndent(out, int_Indent); - out << "sendTime: " << sendTime << " (" << time(NULL)-sendTime << " secs ago)" << std::endl; - - printIndent(out, int_Indent); - - std::string cnv_message(message.begin(), message.end()); - out << "msg: " << cnv_message << std::endl; - - printRsItemEnd(out, "RsPrivateChatMsgConfigItem", indent); - return out; -} -std::ostream& RsPrivateChatDistantInviteConfigItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsPrivateChatDistantInviteConfigItem", indent); + printRsItemBase(out, "RsGxsTunnelDataItem", indent); uint16_t int_Indent = indent + 2; printIndent(out, int_Indent); - out << "radix string: " << encrypted_radix64_string << std::endl; + out << " message id : " << std::hex << unique_item_counter << std::dec << std::endl ; - printIndent(out, int_Indent); - out << "hash: " << hash << std::endl; - - printIndent(out, int_Indent); - out << "destination pgp_id: " << destination_pgp_id << std::endl; - - printIndent(out, int_Indent); - out << "time of validity: " << time_of_validity << std::endl; - - printIndent(out, int_Indent); - out << "time of last hit: " << last_hit_time << std::endl; - - printIndent(out, int_Indent); - out << "flags: " << flags << std::endl; - - printRsItemEnd(out, "RsPrivateChatDistantInviteConfigItem", indent); + printRsItemEnd(out, "RsGxsTunnelDataAckItem", indent); return out; } -std::ostream& RsChatLobbyConfigItem::print(std::ostream &out, uint16_t indent) +std::ostream& RsGxsTunnelStatusItem::print(std::ostream &out, uint16_t indent) { - printRsItemBase(out, "RsChatLobbyConfigItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "lobby_Id: " << lobby_Id << std::endl; - out << "flags : " << flags << std::endl; - - printRsItemEnd(out, "RsChatLobbyConfigItem", indent); - return out; -} -std::ostream& RsChatStatusItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsChatStatusItem", indent); + printRsItemBase(out, "RsGxsTunnelDataItem", indent); uint16_t int_Indent = indent + 2; - printIndent(out, int_Indent); - out << "Status string: " << status_string << std::endl; - out << "Flags : " << std::hex << flags << std::dec << std::endl; - printRsItemEnd(out, "RsChatStatusItem", indent); + printIndent(out, int_Indent); + out << " flags : " << std::hex << flags << std::dec << std::endl ; + + printRsItemEnd(out, "RsGxsTunnelStatusItem", indent); return out; } -std::ostream& RsChatAvatarItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsChatAvatarItem", indent); - uint16_t int_Indent = indent + 2; - printIndent(out, int_Indent); - out << "Image size: " << image_size << std::endl; - printRsItemEnd(out, "RsChatStatusItem", indent); +/*************************************************************************/ - return out; -} RsGxsTunnelDHPublicKeyItem::~RsGxsTunnelDHPublicKeyItem() { BN_free(public_key) ; } -RsItem *RsChatSerialiser::deserialise(void *data, uint32_t *pktsize) -{ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); -#ifdef CHAT_DEBUG - std::cerr << "deserializing packet..."<< std::endl ; +/*************************************************************************/ + +RsItem *RsGxsTunnelSerialiser::deserialise(void *data, uint32_t *pktsize) +{ + uint32_t rstype = getRsItemId(data); + uint32_t rssize = getRsItemSize(data); + +#ifdef GXS_TUNNEL_ITEM_DEBUG + std::cerr << "deserializing packet..."<< std::endl ; #endif - // look what we have... - if (*pktsize < rssize) /* check size */ - { -#ifdef CHAT_DEBUG - std::cerr << "chat deserialisation: not enough size: pktsize=" << *pktsize << ", rssize=" << rssize << std::endl ; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *pktsize = rssize; - - /* ready to load */ - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_CHAT != getRsItemService(rstype))) - { -#ifdef CHAT_DEBUG - std::cerr << "chat deserialisation: wrong type !" << std::endl ; -#endif - return NULL; /* wrong type */ - } - - switch(getRsItemSubType(rstype)) - { - case RS_PKT_SUBTYPE_DEFAULT: return new RsChatMsgItem(data,*pktsize) ; - case RS_PKT_SUBTYPE_PRIVATECHATMSG_CONFIG: return new RsPrivateChatMsgConfigItem(data,*pktsize) ; - case RS_PKT_SUBTYPE_DISTANT_INVITE_CONFIG: return new RsPrivateChatDistantInviteConfigItem(data,*pktsize) ; - case RS_PKT_SUBTYPE_CHAT_STATUS: return new RsChatStatusItem(data,*pktsize) ; - case RS_PKT_SUBTYPE_CHAT_AVATAR: return new RsChatAvatarItem(data,*pktsize) ; - case RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_MSG: return new RsChatLobbyMsgItem(data,*pktsize) ; - case RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE: return new RsChatLobbyInviteItem(data,*pktsize) ; - case RS_PKT_SUBTYPE_CHAT_LOBBY_CHALLENGE: return new RsChatLobbyConnectChallengeItem(data,*pktsize) ; - case RS_PKT_SUBTYPE_CHAT_LOBBY_UNSUBSCRIBE: return new RsChatLobbyUnsubscribeItem(data,*pktsize) ; - case RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_EVENT: return new RsChatLobbyEventItem(data,*pktsize) ; - case RS_PKT_SUBTYPE_CHAT_LOBBY_LIST_REQUEST: return new RsChatLobbyListRequestItem(data,*pktsize) ; - case RS_PKT_SUBTYPE_CHAT_LOBBY_LIST: return new RsChatLobbyListItem(data,*pktsize) ; - case RS_PKT_SUBTYPE_CHAT_LOBBY_CONFIG: return new RsChatLobbyConfigItem(data,*pktsize) ; - case RS_PKT_SUBTYPE_DISTANT_CHAT_DH_PUBLIC_KEY: return new RsChatDHPublicKeyItem(data,*pktsize) ; - default: - std::cerr << "Unknown packet type in chat!" << std::endl ; - return NULL ; - } -} - -uint32_t RsChatMsgItem::serial_size() -{ - uint32_t s = 8; /* header */ - s += 4; /* chatFlags */ - s += 4; /* sendTime */ - s += GetTlvStringSize(message); - - return s; -} - -uint32_t RsChatLobbyUnsubscribeItem::serial_size() -{ - uint32_t s = 8; /* header */ - s += 8; // challenge code - return s ; -} - - -uint32_t RsChatLobbyConnectChallengeItem::serial_size() -{ - uint32_t s = 8; /* header */ - s += 8; // challenge code - return s ; -} -uint32_t RsChatLobbyBouncingObject::serialized_size(bool include_signature) -{ - uint32_t s = 0 ; // no header! - s += 8 ; // lobby_id - s += 8 ; // msg_id - s += GetTlvStringSize(nick) ; // nick - - if(include_signature) - s += signature.TlvSize() ; // signature - - return s ; -} -uint32_t RsChatLobbyEventItem::signed_serial_size() -{ - uint32_t s = 8 ; // header - s += 1 ; // event_type - s += GetTlvStringSize(string1) ; // string1 - s += 4 ; // send time - s += RsChatLobbyBouncingObject::serialized_size(false) ; - - return s ; -} -uint32_t RsChatLobbyEventItem::serial_size() -{ - uint32_t s = 8 ; // header - s += 1 ; // event_type - s += GetTlvStringSize(string1) ; // string1 - s += 4 ; // send time - s += RsChatLobbyBouncingObject::serialized_size(true) ; - - return s ; -} -uint32_t RsChatLobbyListRequestItem::serial_size() -{ - uint32_t s = 8 ; // header - return s ; -} -uint32_t RsChatLobbyListItem::serial_size() -{ - uint32_t s = 8 ; // header - s += 4 ; // number of elements in the vectors - - for(uint32_t i=0;ipublic_key = BN_bin2bn(&((unsigned char *)data)[offset],s,NULL) ; + offset += s ; + + ok &= item->signature.GetTlv(data, rssize, &offset) ; + ok &= item->gxs_key.GetTlv(data, rssize, &offset) ; -#ifdef CHAT_DEBUG - std::cerr << "Building new chat msg config item." << std::endl ; -#endif if (offset != rssize) - std::cerr << "Size error while deserializing." << std::endl ; + { + std::cerr << "RsGxsTunnelDHPublicKeyItem::() Size error while deserializing." << std::endl ; + delete item ; + return NULL ; + } if (!ok) - std::cerr << "Unknown error while deserializing." << std::endl ; + { + std::cerr << "RsGxsTunnelDHPublicKeyItem::() Unknown error while deserializing." << std::endl ; + delete item ; + return NULL ; + } + + return item ; } -/* set data from RsChatMsgItem to RsPrivateChatMsgConfigItem */ -void RsPrivateChatMsgConfigItem::set(RsChatMsgItem *ci, const RsPeerId& /*peerId*/, uint32_t confFlags) +RsGxsTunnelDataItem *deserialise_RsGxsTunnelDataItem(void *dat,uint32_t size) { - PeerId(ci->PeerId()); - configPeerId = ci->PeerId(); - chatFlags = ci->chatFlags; - configFlags = confFlags; - sendTime = ci->sendTime; - message = ci->message; - recvTime = ci->recvTime; + uint32_t offset = 8; // skip the header + uint32_t rssize = getRsItemSize(dat); + bool ok = true ; + + RsGxsTunnelDataItem *item = new RsGxsTunnelDataItem(); + + /* get mandatory parts first */ + + ok &= getRawUInt64(dat, rssize, &offset, &item->unique_item_counter); + ok &= getRawUInt32(dat, rssize, &offset, &item->flags); + ok &= getRawUInt32(dat, rssize, &offset, &item->service_id); + ok &= getRawUInt32(dat, rssize, &offset, &item->data_size); + + if(offset + item->data_size <= size) + { + item->data = (unsigned char*)malloc(item->data_size) ; + + if(dat == NULL) + { + delete item ; + return NULL ; + } + + memcpy(item->data,&((uint8_t*)dat)[offset],item->data_size) ; + offset += item->data_size ; + } + else + ok = false ; + + + if (offset != rssize) + { + std::cerr << "RsGxsTunnelDHPublicKeyItem::() Size error while deserializing." << std::endl ; + delete item ; + return NULL ; + } + if (!ok) + { + std::cerr << "RsGxsTunnelDHPublicKeyItem::() Unknown error while deserializing." << std::endl ; + delete item ; + return NULL ; + } + + return item ; } -/* get data from RsPrivateChatMsgConfigItem to RsChatMsgItem */ -void RsPrivateChatMsgConfigItem::get(RsChatMsgItem *ci) +RsGxsTunnelDataAckItem *deserialise_RsGxsTunnelDataAckItem(void *dat,uint32_t /* size */) { - ci->PeerId(configPeerId); - ci->chatFlags = chatFlags; - //configFlags not used - ci->sendTime = sendTime; - ci->message = message; - ci->recvTime = recvTime; + uint32_t offset = 8; // skip the header + uint32_t rssize = getRsItemSize(dat); + bool ok = true ; + + RsGxsTunnelDataAckItem *item = new RsGxsTunnelDataAckItem(); + + /* get mandatory parts first */ + + ok &= getRawUInt64(dat, rssize, &offset, &item->unique_item_counter); + + if (offset != rssize) + { + std::cerr << "RsGxsTunnelDHPublicKeyItem::() Size error while deserializing." << std::endl ; + delete item ; + return NULL ; + } + if (!ok) + { + std::cerr << "RsGxsTunnelDHPublicKeyItem::() Unknown error while deserializing." << std::endl ; + delete item ; + return NULL ; + } + + return item ; } -RsChatStatusItem::RsChatStatusItem(void *data,uint32_t /*size*/) - : RsChatItem(RS_PKT_SUBTYPE_CHAT_STATUS) +RsGxsTunnelStatusItem *deserialise_RsGxsTunnelStatusItem(void *dat,uint32_t size) { - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; + uint32_t offset = 8; // skip the header + uint32_t rssize = getRsItemSize(dat); + bool ok = true ; -#ifdef CHAT_DEBUG - std::cerr << "Building new chat status item." << std::endl ; -#endif - /* get mandatory parts first */ - ok &= getRawUInt32(data, rssize, &offset, &flags); - ok &= GetTlvString(data, rssize, &offset,TLV_TYPE_STR_MSG, status_string); + RsGxsTunnelStatusItem *item = new RsGxsTunnelStatusItem(); - if (offset != rssize) - std::cerr << "Size error while deserializing." << std::endl ; - if (!ok) - std::cerr << "Unknown error while deserializing." << std::endl ; -} + /* get mandatory parts first */ -RsChatAvatarItem::RsChatAvatarItem(void *data,uint32_t /*size*/) - : RsChatItem(RS_PKT_SUBTYPE_CHAT_AVATAR) -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; + ok &= getRawUInt32(dat, rssize, &offset, &item->flags); -#ifdef CHAT_DEBUG - std::cerr << "Building new chat status item." << std::endl ; -#endif - /* get mandatory parts first */ - ok &= getRawUInt32(data, rssize, &offset,&image_size); + if (offset != rssize) + { + std::cerr << "RsGxsTunnelDHPublicKeyItem::() Size error while deserializing." << std::endl ; + delete item ; + return NULL ; + } + if (!ok) + { + std::cerr << "RsGxsTunnelDHPublicKeyItem::() Unknown error while deserializing." << std::endl ; + delete item ; + return NULL ; + } - // ensure invalid image length does not overflow data - if( (offset + image_size) <= rssize){ - image_data = new unsigned char[image_size] ; - memcpy(image_data,(void*)((unsigned char*)data+offset),image_size) ; - offset += image_size ; - }else{ - ok = false; - std::cerr << "offset+image_size exceeds rssize" << std::endl; - } - - if (offset != rssize) - std::cerr << "Size error while deserializing." << std::endl ; - if (!ok) - std::cerr << "Unknown error while deserializing." << std::endl ; + return item ; } + + + + + + + + + + + + + + diff --git a/libretroshare/src/gxstunnel/rsgxstunnelitems.h b/libretroshare/src/gxstunnel/rsgxstunnelitems.h index 8aea07f67..a5bd1d7b4 100644 --- a/libretroshare/src/gxstunnel/rsgxstunnelitems.h +++ b/libretroshare/src/gxstunnel/rsgxstunnelitems.h @@ -25,6 +25,8 @@ #pragma once +#include + #include "retroshare/rstypes.h" #include "serialiser/rstlvkeys.h" #include "serialiser/rsserviceids.h" @@ -71,8 +73,8 @@ class RsGxsTunnelItem: public RsItem class RsGxsTunnelDataItem: public RsGxsTunnelItem { public: - RsGxsTunnelDataItem() :RsGxsTunnelItem(RS_PKT_SUBTYPE_GXS_TUNNEL_DATA) {} - RsGxsTunnelDataItem(uint8_t subtype) :RsGxsTunnelItem(subtype) {} + RsGxsTunnelDataItem() :RsGxsTunnelItem(RS_PKT_SUBTYPE_GXS_TUNNEL_DATA) { data=NULL ;data_size=0; } + RsGxsTunnelDataItem(uint8_t subtype) :RsGxsTunnelItem(subtype) { data=NULL ;data_size=0; } virtual ~RsGxsTunnelDataItem() {} virtual void clear() {} @@ -154,17 +156,22 @@ class RsGxsTunnelDHPublicKeyItem: public RsGxsTunnelItem class RsGxsTunnelSerialiser: public RsSerialType { - public: - RsGxsTunnelSerialiser() :RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_GXS_TUNNEL) {} +public: + RsGxsTunnelSerialiser() :RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_GXS_TUNNEL) {} - virtual uint32_t size (RsItem *item) - { - return static_cast(item)->serial_size() ; - } - virtual bool serialise(RsItem *item, void *data, uint32_t *size) - { - return static_cast(item)->serialise(data,*size) ; - } - virtual RsGxsTunnelItem *deserialiseGxsTunnelItem(void *data, uint32_t *size) ; + virtual uint32_t size (RsItem *item) + { + return static_cast(item)->serial_size() ; + } + virtual bool serialise(RsItem *item, void *data, uint32_t *size) + { + return static_cast(item)->serialise(data,*size) ; + } + RsItem *deserialise(void *data, uint32_t *pktsize); +private: + static RsGxsTunnelDataAckItem *deserialise_RsGxsTunnelDataAckItem (void *data, uint32_t size) ; + static RsGxsTunnelDataItem *deserialise_RsGxsTunnelDataItem (void *data, uint32_t size) ; + static RsGxsTunnelStatusItem *deserialise_RsGxsTunnelStatusItem (void *data, uint32_t size) ; + static RsGxsTunnelDHPublicKeyItem *deserialise_RsGxsTunnelDHPublicKeyItem(void *data, uint32_t size) ; }; diff --git a/libretroshare/src/retroshare/rsgxstunnel.h b/libretroshare/src/retroshare/rsgxstunnel.h index f7cdc708f..13df25f56 100644 --- a/libretroshare/src/retroshare/rsgxstunnel.h +++ b/libretroshare/src/retroshare/rsgxstunnel.h @@ -85,8 +85,8 @@ public: // Debugging info // //===================================================// - virtual bool getGxsTunnelsInfo(std::vector& infos) =0; - virtual bool getGxsTunnelInfo(const RsGxsTunnelId& tunnel_id,GxsTunnelInfo& info) =0; + //virtual bool getGxsTunnelsInfo(std::vector& infos) =0; + //virtual bool getGxsTunnelInfo(const RsGxsTunnelId& tunnel_id,GxsTunnelInfo& info) =0; // retrieve the routing probabilities @@ -108,7 +108,7 @@ public: // Data is sent through the established tunnel, possibly multiple times, until reception is acknowledged. If the tunnel does not exist, the item is rejected and // an error is issued. In any case, the memory ownership of the data is *not* transferred to the tunnel service, so the client should delete it afterwards, if needed. - virtual bool sendData(const RsGxsTunnelId tunnel_id, uint32_t client_service_id, const uint8_t *data, uint32_t data_size) =0; + virtual bool sendData(const RsGxsTunnelId& tunnel_id, uint32_t client_service_id, const uint8_t *data, uint32_t data_size) =0; // Removes any established tunnel to this GXS id. This makes the tunnel refuse further data, but the tunnel will be however kept alive // until all pending data is flushed. All clients attached to the tunnel will be notified that the tunnel gets closed. diff --git a/libretroshare/src/rsserver/p3face.h b/libretroshare/src/rsserver/p3face.h index 910434309..23efa5866 100644 --- a/libretroshare/src/rsserver/p3face.h +++ b/libretroshare/src/rsserver/p3face.h @@ -39,6 +39,7 @@ #include "util/rsthreads.h" #include "chat/p3chatservice.h" +#include "gxstunnel/p3gxstunnel.h" #include "services/p3msgservice.h" #include "services/p3statusservice.h" @@ -160,6 +161,7 @@ class RsServer: public RsControl, public RsTickingThread p3MsgService *msgSrv; p3ChatService *chatSrv; p3StatusService *mStatusSrv; + p3GxsTunnelService *mGxsTunnels; // This list contains all threaded services. It will be used to shut them down properly. diff --git a/libretroshare/src/rsserver/rsinit.cc b/libretroshare/src/rsserver/rsinit.cc index 1155472e7..f2f775649 100644 --- a/libretroshare/src/rsserver/rsinit.cc +++ b/libretroshare/src/rsserver/rsinit.cc @@ -1474,8 +1474,8 @@ int RsServer::StartupRetroShare() pqih -> addService(tr,true); pqih -> addService(ftserver,true); - p3GxsTunnelService *gxs_tunnels = new p3GxsTunnelService() ; - rsGxsTunnels = gxs_tunnels; + mGxsTunnels = new p3GxsTunnelService(mGxsIdService) ; + rsGxsTunnel = mGxsTunnels; rsDisc = mDisc; rsMsgs = new p3Msgs(msgSrv, chatSrv); @@ -1483,7 +1483,7 @@ int RsServer::StartupRetroShare() // connect components to turtle router. ftserver->connectToTurtleRouter(tr) ; - chatSrv->connectToxsTunnelService(gxs_tunnels) ; + chatSrv->connectToGxsTunnelService(mGxsTunnels) ; gr->connectToTurtleRouter(tr) ; #ifdef ENABLE_GROUTER msgSrv->connectToGlobalRouter(gr) ;