diff --git a/RetroShare.pro b/RetroShare.pro index dc590dd17..58ae659ab 100644 --- a/RetroShare.pro +++ b/RetroShare.pro @@ -55,6 +55,12 @@ retroshare_service { retroshare_service.target = retroshare_service } +retroshare_friendserver { + SUBDIRS += retroshare_friendserver + retroshare_friendserver.file = retroshare-friendserver/src/retroshare-friendserver.pro + retroshare_friendserver.depends = libretroshare + retroshare_friendserver.target = retroshare_friendserver +} retroshare_plugins { SUBDIRS += plugins plugins.file = plugins/plugins.pro diff --git a/libretroshare/src/rsitems/rsserviceids.h b/libretroshare/src/rsitems/rsserviceids.h index ead349e32..693a1b149 100644 --- a/libretroshare/src/rsitems/rsserviceids.h +++ b/libretroshare/src/rsitems/rsserviceids.h @@ -49,7 +49,8 @@ enum class RsServiceType : uint16_t GXS_TUNNEL = 0x0028, BANLIST = 0x0101, STATUS = 0x0102, - NXS = 0x0200, + FRIEND_SERVER = 0x0103, + NXS = 0x0200, GXSID = 0x0211, PHOTO = 0x0212, WIKI = 0x0213, @@ -109,6 +110,8 @@ RS_DEPRECATED_FOR(RsServiceType) const uint16_t RS_SERVICE_TYPE_DISTANT_CHAT = RS_DEPRECATED_FOR(RsServiceType) const uint16_t RS_SERVICE_TYPE_GXS_TUNNEL = 0x0028; RS_DEPRECATED_FOR(RsServiceType) const uint16_t RS_SERVICE_TYPE_BANLIST = 0x0101; RS_DEPRECATED_FOR(RsServiceType) const uint16_t RS_SERVICE_TYPE_STATUS = 0x0102; +RS_DEPRECATED_FOR(RsServiceType) const uint16_t RS_SERVICE_TYPE_FRIEND_SERVER = 0x0103; + /// Rs Network Exchange Service RS_DEPRECATED_FOR(RsServiceType) const uint16_t RS_SERVICE_TYPE_NXS = 0x0200; RS_DEPRECATED_FOR(RsServiceType) const uint16_t RS_SERVICE_GXS_TYPE_GXSID = 0x0211; diff --git a/retroshare-friendserver/src/friendserver.cc b/retroshare-friendserver/src/friendserver.cc new file mode 100644 index 000000000..10584d401 --- /dev/null +++ b/retroshare-friendserver/src/friendserver.cc @@ -0,0 +1,32 @@ +#include "util/rsdebug.h" + +#include "friendserver.h" +#include "fsitem.h" + +void FriendServer::threadTick() +{ + // Listen to the network interface, capture incoming data etc. + + std::this_thread::sleep_for(std::chrono::seconds(1)); +} + +FriendServer::FriendServer(const std::string& base_dir) +{ + RsDbg() << "Creating friend server." << std::endl; + mBaseDirectory = base_dir; +} + +void FriendServer::run() +{ + // 1 - create network interface. + + mni = new FsNetworkInterface; + + RsSerialiser *rss = new RsSerialiser ; + rss->addSerialType(new FsSerializer) ; + + pqi = new pqistreamer(rss, RsPeerId(), mni,BIN_FLAGS_READABLE); + + while(!shouldStop()) { threadTick() ; } +} + diff --git a/retroshare-friendserver/src/friendserver.h b/retroshare-friendserver/src/friendserver.h new file mode 100644 index 000000000..0be516508 --- /dev/null +++ b/retroshare-friendserver/src/friendserver.h @@ -0,0 +1,42 @@ +/* + * RetroShare Friend Server + * Copyright (C) 2021-2021 retroshare team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * SPDX-FileCopyrightText: Retroshare Team + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +#pragma once + +#include "util/rsthreads.h" +#include "pqi/pqistreamer.h" + +#include "network.h" + +class FriendServer : public RsTickingThread +{ + public: + FriendServer(const std::string& base_directory); + + private: + virtual void threadTick() override; + virtual void run() override; + + FsNetworkInterface *mni; + pqistreamer *pqi; + + std::string mBaseDirectory; +}; diff --git a/retroshare-friendserver/src/fsitem.h b/retroshare-friendserver/src/fsitem.h new file mode 100644 index 000000000..ff03be4f9 --- /dev/null +++ b/retroshare-friendserver/src/fsitem.h @@ -0,0 +1,25 @@ +#include "serialiser/rsserial.h" +#include "serialiser/rsserializer.h" + +#include "rsitems/rsitem.h" +#include "rsitems/rsserviceids.h" +#include "rsitems/itempriorities.h" + +class FsItem: public RsItem +{ +public: + FsItem(uint8_t item_subtype) : RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_FRIEND_SERVER,item_subtype) + { + setPriorityLevel(QOS_PRIORITY_DEFAULT) ; + } + + virtual ~FsItem() {} + virtual void clear() {} +}; + +struct FsSerializer : RsServiceSerializer +{ + FsSerializer(RsSerializationFlags flags = RsSerializationFlags::NONE): RsServiceSerializer(RS_SERVICE_TYPE_FRIEND_SERVER, flags) {} + + virtual RsItem *create_item(uint16_t service_id,uint8_t item_sub_id) const {}; +}; diff --git a/retroshare-friendserver/src/network.cc b/retroshare-friendserver/src/network.cc new file mode 100644 index 000000000..5aab08cae --- /dev/null +++ b/retroshare-friendserver/src/network.cc @@ -0,0 +1,89 @@ +/* + * RetroShare Friend Server + * Copyright (C) 2021-2021 retroshare team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * SPDX-FileCopyrightText: Retroshare Team + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "util/rsnet.h" +#include "util/rsprint.h" +#include "util/rsdebug.h" + +#include "network.h" + +FsNetworkInterface::FsNetworkInterface() +{ + mClintListn = 0; + start(); +} +void FsNetworkInterface::start() +{ + struct sockaddr_in ipOfServer; + + mClintListn = socket(AF_INET, SOCK_STREAM, 0); // creating socket + + memset(&ipOfServer, '0', sizeof(ipOfServer)); + + ipOfServer.sin_family = AF_INET; + ipOfServer.sin_addr.s_addr = htonl(INADDR_ANY); + ipOfServer.sin_port = htons(2017); // this is the port number of running server + + bind(mClintListn, (struct sockaddr*)&ipOfServer , sizeof(ipOfServer)); + listen(mClintListn , 20); + + RsDbg() << "Network interface now listening for TCP on " << sockaddr_storage_tostring( *(sockaddr_storage*)&ipOfServer) << std::endl; +} + +int FsNetworkInterface::close() +{ + RsDbg() << "Stopping network interface" << std::endl; + return 1; +} + +int FsNetworkInterface::tick() +{ + int clintConnt = accept(mClintListn, (struct sockaddr*)NULL, NULL); + + char inBuffer[1025]; + int readbytes = read(clintConnt, inBuffer, strlen(inBuffer)); + + ::close(clintConnt); + + // display some debug info + + if(readbytes > 0) + { + RsDbg() << "Received the following bytes: " << RsUtil::BinToHex( reinterpret_cast(inBuffer),readbytes,50) << std::endl; + RsDbg() << "Received the following bytes: " << std::string(inBuffer,readbytes) << std::endl; + } + else + std::this_thread::sleep_for(std::chrono::seconds(1)); + + return true; +} + diff --git a/retroshare-friendserver/src/network.h b/retroshare-friendserver/src/network.h new file mode 100644 index 000000000..8417927e8 --- /dev/null +++ b/retroshare-friendserver/src/network.h @@ -0,0 +1,62 @@ +/* + * RetroShare Friend Server + * Copyright (C) 2021-2021 retroshare team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * SPDX-FileCopyrightText: Retroshare Team + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +#pragma once + +#include "util/rsthreads.h" +#include "pqi/pqi_base.h" + +class FsNetworkInterface: public BinInterface +{ +public: + FsNetworkInterface() ; + + void start() ; + + // Implements BinInterface methods + + virtual int tick() override; + + virtual int senddata(void *data, int len) override; + virtual int readdata(void *data, int len) override; + + virtual int netstatus() override; + virtual int isactive() override; + virtual bool moretoread(uint32_t usec) override; + virtual bool cansend(uint32_t usec) override; + + virtual int close() override; + + /** + * If hashing data + **/ + virtual RsFileHash gethash() override { return RsFileHash() ; } + virtual uint64_t bytecount() override { return mTotalBytes; } + + virtual bool bandwidthLimited() override { return false; } +private: + + void initListening(); + void stopListening(); + + int mClintListn ; + uint64_t mTotalBytes; +}; diff --git a/retroshare-friendserver/src/retroshare-friendserver.cc b/retroshare-friendserver/src/retroshare-friendserver.cc new file mode 100644 index 000000000..1be8e1f4e --- /dev/null +++ b/retroshare-friendserver/src/retroshare-friendserver.cc @@ -0,0 +1,61 @@ +/* + * RetroShare Service + * Copyright (C) 2021-2021 retroshare team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * SPDX-FileCopyrightText: Retroshare Team + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +#include "util/stacktrace.h" +#include "util/argstream.h" +#include "util/rstime.h" +#include "util/rsdebug.h" + +#include "friendserver.h" + +int main(int argc, char* argv[]) +{ + RsInfo() << "\n" << + "+================================================================+\n" + "| o---o o |\n" + "| \\ / - Retroshare Friend Server - / \\ |\n" + "| o o---o |\n" + "+================================================================+" + << std::endl << std::endl; + + //RsInit::InitRsConfig(); + //RsControl::earlyInitNotificationSystem(); + + std::string base_directory; + + argstream as(argc,argv); + + as >> parameter( 'c',"base-dir", base_directory, "directory", "Set base directory.", false ) + >> help( 'h', "help", "Display this Help" ); + + as.defaultErrorHandling(true, true); + + // Now start the real thing. + + FriendServer fs(base_directory); + fs.start(); + + while(fs.isRunning()) + std::this_thread::sleep_for(std::chrono::seconds(1)); + + return 0; +} + diff --git a/retroshare-friendserver/src/retroshare-friendserver.pro b/retroshare-friendserver/src/retroshare-friendserver.pro new file mode 100644 index 000000000..79986b461 --- /dev/null +++ b/retroshare-friendserver/src/retroshare-friendserver.pro @@ -0,0 +1,43 @@ +# RetroShare service qmake build script +# +# Copyright (C) 2021-2021, retroshare team +# +# This program is free software: you can redistribute it and/or modify it under +# the terms of the GNU Affero General Public License as published by the +# Free Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. +# See the GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License along +# with this program. If not, see . +# +# SPDX-FileCopyrightText: Retroshare Team +# SPDX-License-Identifier: AGPL-3.0-or-later + +!include("../../retroshare.pri"): error("Could not include file ../../retroshare.pri") + +TARGET = retroshare-friendserver + +!include("../../libretroshare/src/use_libretroshare.pri"):error("Including") + +SOURCES += retroshare-friendserver.cc \ + friendserver.cc \ + network.cc + +HEADERS += friendserver.h \ + network.h \ + fsitem.h + +################################# Linux ########################################## + +unix { + target.path = "$${RS_BIN_DIR}" + INSTALLS += target +} + +################################### COMMON stuff ################################## + diff --git a/retroshare.pri b/retroshare.pri index 8e59df32d..3fcad4a78 100644 --- a/retroshare.pri +++ b/retroshare.pri @@ -50,6 +50,11 @@ retroshare_plugins:CONFIG -= no_retroshare_plugins CONFIG *= retroshare_service no_retroshare_service:CONFIG -= retroshare_service +# To disable RetroShare FriendServer append the following assignation to +# qmake command line "CONFIG+=no_rs_friendserver" +CONFIG *= retroshare_friendserver +no_rs_friendserver:CONFIG -= retroshare_friendserver + # To disable SQLCipher support append the following assignation to qmake # command line "CONFIG+=no_sqlcipher" CONFIG *= sqlcipher