mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
added base network layer for friend server. Not working yet.
This commit is contained in:
parent
d9c91ea41d
commit
d97ad8099c
@ -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
|
||||
|
@ -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;
|
||||
|
32
retroshare-friendserver/src/friendserver.cc
Normal file
32
retroshare-friendserver/src/friendserver.cc
Normal file
@ -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() ; }
|
||||
}
|
||||
|
42
retroshare-friendserver/src/friendserver.h
Normal file
42
retroshare-friendserver/src/friendserver.h
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* RetroShare Friend Server
|
||||
* Copyright (C) 2021-2021 retroshare team <retroshare.project@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* SPDX-FileCopyrightText: Retroshare Team <contact@retroshare.cc>
|
||||
* 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;
|
||||
};
|
25
retroshare-friendserver/src/fsitem.h
Normal file
25
retroshare-friendserver/src/fsitem.h
Normal file
@ -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 {};
|
||||
};
|
89
retroshare-friendserver/src/network.cc
Normal file
89
retroshare-friendserver/src/network.cc
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* RetroShare Friend Server
|
||||
* Copyright (C) 2021-2021 retroshare team <retroshare.project@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* SPDX-FileCopyrightText: Retroshare Team <contact@retroshare.cc>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#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<unsigned char*>(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;
|
||||
}
|
||||
|
62
retroshare-friendserver/src/network.h
Normal file
62
retroshare-friendserver/src/network.h
Normal file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* RetroShare Friend Server
|
||||
* Copyright (C) 2021-2021 retroshare team <retroshare.project@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* SPDX-FileCopyrightText: Retroshare Team <contact@retroshare.cc>
|
||||
* 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;
|
||||
};
|
61
retroshare-friendserver/src/retroshare-friendserver.cc
Normal file
61
retroshare-friendserver/src/retroshare-friendserver.cc
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* RetroShare Service
|
||||
* Copyright (C) 2021-2021 retroshare team <retroshare.project@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* SPDX-FileCopyrightText: Retroshare Team <contact@retroshare.cc>
|
||||
* 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;
|
||||
}
|
||||
|
43
retroshare-friendserver/src/retroshare-friendserver.pro
Normal file
43
retroshare-friendserver/src/retroshare-friendserver.pro
Normal file
@ -0,0 +1,43 @@
|
||||
# RetroShare service qmake build script
|
||||
#
|
||||
# Copyright (C) 2021-2021, retroshare team <retroshare.project@gmail.com>
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# SPDX-FileCopyrightText: Retroshare Team <contact@retroshare.cc>
|
||||
# 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 ##################################
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user