├── gui ├── sounds │ ├── ring3.wav │ ├── ringin.wav │ ├── incomingcall.wav │ ├── outgoingcall.wav │ └── outgoingcallbusy.wav ├── images │ ├── call-hold.png │ ├── call-start.png │ ├── call-stop.png │ ├── camera-off.png │ ├── camera-on.png │ ├── call-hold-22.png │ ├── call-start-22.png │ ├── call-stop-22.png │ ├── video-icon-on.png │ ├── video-icon-big.png │ ├── video-icon-off.png │ ├── audio-volume-high.png │ ├── audio-volume-muted.png │ ├── audio-volume-muted-22.png │ ├── audio-volume-medium-22.png │ ├── self_undeafened.svg │ ├── deafened_self.svg │ └── talking_off.svg ├── EasyTransport_images.qrc ├── EasyTransportNotify.cpp ├── NEMainpage.h ├── paintwidget.h ├── NEMainpage.cpp ├── EasyTransportNotify.h ├── NEMainpage.ui └── paintwidget.cpp ├── cptest ├── README.md ├── EasyTransport.pro ├── EasyTransportPlugin.h ├── interface └── rsEasyTransport.h ├── services ├── p3EasyTransport.h ├── rsEasyTransportItems.h ├── rsEasyTransportItems.cc └── p3EasyTransport.cc └── EasyTransportPlugin.cpp /gui/sounds/ring3.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chozabu/RSEasyTransport/master/gui/sounds/ring3.wav -------------------------------------------------------------------------------- /gui/sounds/ringin.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chozabu/RSEasyTransport/master/gui/sounds/ringin.wav -------------------------------------------------------------------------------- /gui/images/call-hold.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chozabu/RSEasyTransport/master/gui/images/call-hold.png -------------------------------------------------------------------------------- /gui/images/call-start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chozabu/RSEasyTransport/master/gui/images/call-start.png -------------------------------------------------------------------------------- /gui/images/call-stop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chozabu/RSEasyTransport/master/gui/images/call-stop.png -------------------------------------------------------------------------------- /gui/images/camera-off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chozabu/RSEasyTransport/master/gui/images/camera-off.png -------------------------------------------------------------------------------- /gui/images/camera-on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chozabu/RSEasyTransport/master/gui/images/camera-on.png -------------------------------------------------------------------------------- /gui/images/call-hold-22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chozabu/RSEasyTransport/master/gui/images/call-hold-22.png -------------------------------------------------------------------------------- /gui/images/call-start-22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chozabu/RSEasyTransport/master/gui/images/call-start-22.png -------------------------------------------------------------------------------- /gui/images/call-stop-22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chozabu/RSEasyTransport/master/gui/images/call-stop-22.png -------------------------------------------------------------------------------- /gui/images/video-icon-on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chozabu/RSEasyTransport/master/gui/images/video-icon-on.png -------------------------------------------------------------------------------- /gui/sounds/incomingcall.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chozabu/RSEasyTransport/master/gui/sounds/incomingcall.wav -------------------------------------------------------------------------------- /gui/sounds/outgoingcall.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chozabu/RSEasyTransport/master/gui/sounds/outgoingcall.wav -------------------------------------------------------------------------------- /gui/images/video-icon-big.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chozabu/RSEasyTransport/master/gui/images/video-icon-big.png -------------------------------------------------------------------------------- /gui/images/video-icon-off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chozabu/RSEasyTransport/master/gui/images/video-icon-off.png -------------------------------------------------------------------------------- /gui/sounds/outgoingcallbusy.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chozabu/RSEasyTransport/master/gui/sounds/outgoingcallbusy.wav -------------------------------------------------------------------------------- /gui/images/audio-volume-high.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chozabu/RSEasyTransport/master/gui/images/audio-volume-high.png -------------------------------------------------------------------------------- /gui/images/audio-volume-muted.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chozabu/RSEasyTransport/master/gui/images/audio-volume-muted.png -------------------------------------------------------------------------------- /gui/images/audio-volume-muted-22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chozabu/RSEasyTransport/master/gui/images/audio-volume-muted-22.png -------------------------------------------------------------------------------- /gui/images/audio-volume-medium-22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chozabu/RSEasyTransport/master/gui/images/audio-volume-medium-22.png -------------------------------------------------------------------------------- /cptest: -------------------------------------------------------------------------------- 1 | kdesudo -u retrotester cp lib*.so* /home/retrotester/.retroshare/extensions6/ 2 | kdesudo -u retrotester /home/chozabu/git/RetroShare/retroshare-gui/src/RetroShare 3 | 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | RS .6 EasyTransport Plugin 2 | ================== 3 | 4 | This plugin should provide a simple interface to other plugins, allowing them to talk across a network easily 5 | 6 | ##Example 7 | 8 | ###include easy transport 9 | 10 | #include "interface/rsEasyTransport.h" 11 | 12 | 13 | ###connect 14 | 15 | connect(rsEasyTransport->mNotify, SIGNAL(NeMsgArrived(RsPeerId,QString)), this , SLOT(NeMsgArrived(RsPeerId,QString))); 16 | 17 | ###send message 18 | 19 | rsEasyTransport->msg_all(ui->lineEdit->text().toStdString()); 20 | 21 | 22 | 23 | This is based on the ExamplePlugin, and in turn VOIP plugin. 24 | 25 | -------------------------------------------------------------------------------- /gui/EasyTransport_images.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | images/audio-volume-high.png 4 | images/muted_self.svg 5 | images/audio-volume-muted.png 6 | images/talking_on.svg 7 | images/talking_off.svg 8 | images/call-start.png 9 | images/call-stop.png 10 | images/call-hold.png 11 | images/camera-on.png 12 | images/camera-off.png 13 | images/video-icon-big.png 14 | images/video-icon-on.png 15 | images/video-icon-off.png 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /gui/EasyTransportNotify.cpp: -------------------------------------------------------------------------------- 1 | #include "EasyTransportNotify.h" 2 | 3 | EasyTransportNotify::EasyTransportNotify(QObject *parent) : QObject(parent) 4 | { 5 | 6 | } 7 | 8 | void EasyTransportNotify::notifyReceivedPaint(const RsPeerId &peer_id, int x, int y) 9 | { 10 | std::cout << "pNotify Recvd paint from: " << peer_id; 11 | std::cout << " at " << x << " , " << y; 12 | std::cout << std::endl; 13 | emit NePaintArrived(peer_id, x, y); 14 | } 15 | 16 | 17 | void EasyTransportNotify::notifyReceivedMsg(const RsPeerId& peer_id, QString str) 18 | { 19 | std::cout << "pNotify Recvd Packet from: " << peer_id; 20 | std::cout << " saying " << str.toStdString(); 21 | std::cout << std::endl; 22 | emit NeMsgArrived(peer_id, str) ; 23 | } 24 | -------------------------------------------------------------------------------- /gui/NEMainpage.h: -------------------------------------------------------------------------------- 1 | /* This is the main page displayed by the plugin */ 2 | #ifndef NEMAINPAGE_H 3 | #define NEMAINPAGE_H 4 | 5 | #include 6 | #include 7 | #include 8 | #include "gui/EasyTransportNotify.h" 9 | 10 | 11 | 12 | #include 13 | 14 | namespace Ui { 15 | class NEMainpage; 16 | } 17 | 18 | class NEMainpage : public MainPage 19 | { 20 | Q_OBJECT 21 | 22 | public: 23 | explicit NEMainpage(QWidget *parent, EasyTransportNotify *notify); 24 | ~NEMainpage(); 25 | 26 | private slots: 27 | void mmEvent(int x, int y); 28 | void on_pingAllButton_clicked(); 29 | void NeMsgArrived(const RsPeerId &peer_id, QString str); 30 | 31 | void on_broadcastButton_clicked(); 32 | 33 | void NePaintArrived(const RsPeerId &peer_id, int x, int y); 34 | private: 35 | Ui::NEMainpage *ui; 36 | EasyTransportNotify *mNotify; 37 | }; 38 | 39 | #endif // NEMAINPAGE_H 40 | -------------------------------------------------------------------------------- /gui/paintwidget.h: -------------------------------------------------------------------------------- 1 | /* this is just a local widget that can be drawn on */ 2 | #ifndef PAINTWIDGET_H 3 | #define PAINTWIDGET_H 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | class TopJCDialog; 11 | 12 | class PaintWidget : public QWidget 13 | { 14 | Q_OBJECT 15 | public: 16 | explicit PaintWidget(QWidget *parent = 0); 17 | void setImage(const QImage&); 18 | QImage getImage(); 19 | 20 | void fillImage(QColor color); 21 | virtual void paintAt(int x, int y); 22 | 23 | QColor color; 24 | uint8_t penWidth; 25 | TopJCDialog* tjd; 26 | 27 | signals: 28 | void haveUpdate(); 29 | void mmEvent(int x, int y); 30 | 31 | 32 | public slots: 33 | 34 | protected: 35 | virtual void mouseReleaseEvent(QMouseEvent * event); 36 | virtual void paintEvent(QPaintEvent *); 37 | virtual void mouseMoveEvent(QMouseEvent *); 38 | 39 | private: 40 | QImage image; 41 | 42 | }; 43 | 44 | #endif // PAINTWIDGET_H 45 | -------------------------------------------------------------------------------- /gui/NEMainpage.cpp: -------------------------------------------------------------------------------- 1 | #include "NEMainpage.h" 2 | #include "ui_NEMainpage.h" 3 | //#include "services/p3EasyTransport.h" 4 | #include "interface/rsEasyTransport.h" 5 | 6 | 7 | NEMainpage::NEMainpage(QWidget *parent, EasyTransportNotify *notify) : 8 | MainPage(parent), 9 | mNotify(notify), 10 | ui(new Ui::NEMainpage) 11 | { 12 | ui->setupUi(this); 13 | 14 | connect(mNotify, SIGNAL(NeMsgArrived(RsPeerId,QString)), this , SLOT(NeMsgArrived(RsPeerId,QString))); 15 | connect(mNotify, SIGNAL(NePaintArrived(RsPeerId,int,int)), this , SLOT(NePaintArrived(RsPeerId,int,int))); 16 | //ui->listWidget->addItem("str"); 17 | connect(ui->paintWidget, SIGNAL(mmEvent(int,int)), this, SLOT(mmEvent(int,int))); 18 | 19 | } 20 | 21 | NEMainpage::~NEMainpage() 22 | { 23 | delete ui; 24 | } 25 | 26 | void NEMainpage::mmEvent(int x, int y) 27 | { 28 | rsEasyTransport->broadcast_paint(x,y); 29 | } 30 | 31 | void NEMainpage::on_pingAllButton_clicked() 32 | { 33 | rsEasyTransport->ping_all(); 34 | NeMsgArrived(rsPeers->getOwnId(),"ping"); 35 | } 36 | 37 | 38 | void NEMainpage::NeMsgArrived(const RsPeerId &peer_id, QString str) 39 | { 40 | 41 | std::cout << "GUI got Packet from: " << peer_id; 42 | std::cout << " saying " << str.toStdString(); 43 | std::cout << std::endl; 44 | 45 | QString output = QString::fromStdString(rsPeers->getPeerName(peer_id)); 46 | output+=": "; 47 | output+=str; 48 | ui->listWidget->addItem(output); 49 | } 50 | void NEMainpage::NePaintArrived(const RsPeerId &peer_id, int x, int y) 51 | { 52 | 53 | std::cout << "GUI got Paint from: " << peer_id; 54 | std::cout << std::endl; 55 | 56 | ui->paintWidget->paintAt(x,y); 57 | } 58 | 59 | void NEMainpage::on_broadcastButton_clicked() 60 | { 61 | rsEasyTransport->msg_all(ui->msgInput->text().toStdString()); 62 | NeMsgArrived(rsPeers->getOwnId(),ui->msgInput->text()); 63 | ui->msgInput->clear(); 64 | } 65 | -------------------------------------------------------------------------------- /EasyTransport.pro: -------------------------------------------------------------------------------- 1 | !include("../Common/retroshare_plugin.pri"): error("Could not include file ../Common/retroshare_plugin.pri") 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4) { 4 | # Qt 5 5 | QT += widgets 6 | } 7 | 8 | exists($$[QMAKE_MKSPECS]/features/mobility.prf) { 9 | CONFIG += mobility 10 | } else { 11 | QT += multimedia 12 | } 13 | CONFIG += qt uic qrc resources 14 | MOBILITY = multimedia 15 | 16 | DEPENDPATH += ../../retroshare-gui/src/temp/ui ../../libretroshare/src 17 | INCLUDEPATH += ../../retroshare-gui/src/temp/ui ../../libretroshare/src 18 | 19 | #################################### Windows ##################################### 20 | 21 | linux-* { 22 | INCLUDEPATH += /usr/include 23 | LIBS += $$system(pkg-config --libs opencv) 24 | } 25 | 26 | win32 { 27 | LIBS_DIR = $$PWD/../../../libs 28 | LIBS += -L"$$LIBS_DIR/lib/opencv" 29 | 30 | OPENCV_VERSION = 249 31 | LIBS += -lopencv_core$$OPENCV_VERSION -lopencv_highgui$$OPENCV_VERSION -lopencv_imgproc$$OPENCV_VERSION -llibjpeg -llibtiff -llibpng -llibjasper -lIlmImf -lole32 -loleaut32 -luuid -lavicap32 -lavifil32 -lvfw32 -lz 32 | } 33 | 34 | QMAKE_CXXFLAGS *= -Wall 35 | 36 | SOURCES = EasyTransportPlugin.cpp \ 37 | services/p3EasyTransport.cc \ 38 | services/rsEasyTransportItems.cc \ 39 | gui/NEMainpage.cpp \ 40 | gui/EasyTransportNotify.cpp \ 41 | gui/paintwidget.cpp 42 | 43 | HEADERS = EasyTransportPlugin.h \ 44 | services/p3EasyTransport.h \ 45 | services/rsEasyTransportItems.h \ 46 | interface/rsEasyTransport.h \ 47 | gui/NEMainpage.h \ 48 | gui/EasyTransportNotify.h \ 49 | gui/paintwidget.h 50 | 51 | #FORMS = gui/AudioInputConfig.ui 52 | 53 | TARGET = EasyTransport 54 | 55 | RESOURCES = gui/EasyTransport_images.qrc 56 | 57 | 58 | LIBS += -lspeex -lspeexdsp 59 | 60 | FORMS += \ 61 | gui/NEMainpage.ui 62 | -------------------------------------------------------------------------------- /gui/EasyTransportNotify.h: -------------------------------------------------------------------------------- 1 | /**************************************************************** 2 | * RetroShare is distributed under the following license: 3 | * 4 | * Copyright (C) 2015 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301, USA. 20 | ****************************************************************/ 21 | 22 | // This class is a Qt object to get notification from the plugin's service threads, 23 | // and responsible to pass the info the the GUI part. 24 | // 25 | // Because the GUI part is async-ed with the service, it is crucial to use the 26 | // QObject connect system to communicate between the p3Service and the gui part (handled by Qt) 27 | // 28 | #ifndef NETEXAMPLENOTIFY_H 29 | #define NETEXAMPLENOTIFY_H 30 | 31 | #include 32 | 33 | #include 34 | 35 | class EasyTransportNotify : public QObject 36 | { 37 | Q_OBJECT 38 | public: 39 | explicit EasyTransportNotify(QObject *parent = 0); 40 | void notifyReceivedPaint(const RsPeerId &peer_id, int x, int y) ; 41 | void notifyReceivedMsg(const RsPeerId &peer_id, QString str) ; 42 | 43 | signals: 44 | void NeMsgArrived(const RsPeerId &peer_id, QString str) ; // emitted when the peer gets a msg 45 | void NePaintArrived(const RsPeerId &peer_id, int x, int y) ; 46 | 47 | public slots: 48 | }; 49 | 50 | #endif // NETEXAMPLENOTIFY_H 51 | -------------------------------------------------------------------------------- /gui/NEMainpage.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | NEMainpage 4 | 5 | 6 | 7 | 0 8 | 0 9 | 685 10 | 632 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 310 20 | 230 21 | 80 22 | 23 23 | 24 | 25 | 26 | Ping All 27 | 28 | 29 | 30 | 31 | 32 | 10 33 | 10 34 | 291 35 | 241 36 | 37 | 38 | 39 | 40 | 41 | 42 | 310 43 | 270 44 | 80 45 | 23 46 | 47 | 48 | 49 | Broadcast 50 | 51 | 52 | 53 | 54 | 55 | 10 56 | 270 57 | 291 58 | 23 59 | 60 | 61 | 62 | 63 | 64 | 65 | 19 66 | 319 67 | 571 68 | 271 69 | 70 | 71 | 72 | 73 | 74 | 75 | PaintWidget 76 | QWidget 77 |
gui/paintwidget.h
78 | 1 79 |
80 |
81 | 82 | 83 |
84 | -------------------------------------------------------------------------------- /gui/paintwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "paintwidget.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | PaintWidget::PaintWidget(QWidget *parent) : 10 | QWidget(parent),image(600,300,QImage::Format_RGB32),color(Qt::black),penWidth(8) 11 | { 12 | image.fill(qRgb(255, 255, 255)); 13 | } 14 | 15 | void PaintWidget::setImage(const QImage &img){ 16 | image=img.copy(); 17 | update(); 18 | } 19 | 20 | QImage PaintWidget::getImage(){ 21 | return image; 22 | } 23 | 24 | void PaintWidget::fillImage(QColor color){ 25 | image.fill(qRgb(255, 255, 255)); 26 | update(); 27 | } 28 | 29 | void PaintWidget::mouseMoveEvent(QMouseEvent *event) 30 | { 31 | QPainter p(&image); 32 | p.setPen(color); 33 | p.setBrush(color); 34 | QPoint pos = event->pos(); 35 | if(penWidth==1){ 36 | p.drawPoint(pos); 37 | }else{ 38 | p.drawEllipse(pos,penWidth/2,penWidth/2); 39 | } 40 | //check if u want to clear Jenster-- 41 | // if (event->button() == Qt::RightButton) image.fill(qRgb(255, 255, 255)); 42 | 43 | // trigger repaint of widget 44 | update(); 45 | emit mmEvent(pos.x(), pos.y()); 46 | //tjd->paintMouseMove(event); 47 | } 48 | 49 | 50 | void PaintWidget::paintAt(int x, int y) 51 | { 52 | QPainter p(&image); 53 | p.setPen(color); 54 | p.setBrush(color); 55 | if(penWidth==1){ 56 | p.drawPoint(x,y); 57 | }else{ 58 | p.drawEllipse(x,y,penWidth/2,penWidth/2); 59 | } 60 | // trigger repaint of widget 61 | update(); 62 | } 63 | 64 | qint64 getImgSize(QImage image){ 65 | QByteArray ba; 66 | QBuffer buffer(&ba); 67 | buffer.open(QIODevice::WriteOnly); 68 | image.save(&buffer, "PNG"); 69 | return buffer.buffer().toBase64().size(); 70 | } 71 | 72 | void PaintWidget::mouseReleaseEvent(QMouseEvent *event){ 73 | std::cout<<"PaintWidgte::mouseReleseEvent()"<button() == Qt::RightButton) { image.fill(qRgb(255, 255, 255));update(); } 76 | //check to see if we want to send to clipboard 77 | if (event->button() == Qt::MiddleButton) { 78 | QImage img = image.scaledToWidth(image.width()*0.5); 79 | while(getImgSize(img)> 5500){ 80 | img = img.scaledToWidth(img.width()*0.8); 81 | } 82 | QApplication::clipboard()->setImage(img); 83 | } 84 | 85 | 86 | 87 | emit haveUpdate(); 88 | } 89 | 90 | void PaintWidget::paintEvent(QPaintEvent *event) 91 | { 92 | QPainter p(this); 93 | p.drawImage(0,0,image); 94 | } 95 | -------------------------------------------------------------------------------- /EasyTransportPlugin.h: -------------------------------------------------------------------------------- 1 | /* this is the central part of the plugin */ 2 | /**************************************************************** 3 | * RetroShare is distributed under the following license: 4 | * 5 | * Copyright (C) 2015 6 | * 7 | * This program is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU General Public License 9 | * as published by the Free Software Foundation; either version 2 10 | * of the License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 | * Boston, MA 02110-1301, USA. 21 | ****************************************************************/ 22 | #pragma once 23 | 24 | /*EasyTransport*/ 25 | #include "services/p3EasyTransport.h" 26 | 27 | /*libretroshare"*/ 28 | #include 29 | 30 | #include "gui/NEMainpage.h" 31 | 32 | class EasyTransportGUIHandler ; 33 | class EasyTransportNotify ; 34 | 35 | class EasyTransportPlugin: public RsPlugin 36 | { 37 | public: 38 | EasyTransportPlugin() ; 39 | virtual ~EasyTransportPlugin() {} 40 | 41 | virtual p3Service *p3_service() const ; 42 | virtual uint16_t rs_service_id() const { return RS_SERVICE_TYPE_EasyTransport_PLUGIN ; } 43 | //virtual ConfigPage *qt_config_page() const ; 44 | virtual QDialog *qt_about_page() const ; 45 | //virtual ChatWidgetHolder *qt_get_chat_widget_holder(ChatWidget *chatWidget) const ; 46 | 47 | virtual QIcon *qt_icon() const; 48 | virtual QTranslator *qt_translator(QApplication *app, const QString& languageCode, const QString& externalDir) const; 49 | virtual void qt_sound_events(SoundEvents &events) const; 50 | 51 | virtual void getPluginVersion(int& major, int& minor, int &build, int& svn_rev) const ; 52 | virtual void setPlugInHandler(RsPluginHandler *pgHandler); 53 | 54 | virtual std::string configurationFileName() const { return "net_example.cfg" ; } 55 | 56 | virtual std::string getShortPluginDescription() const ; 57 | virtual std::string getPluginName() const; 58 | virtual void setInterfaces(RsPlugInInterfaces& interfaces); 59 | 60 | //================================== RsPlugin Notify ==================================// 61 | //virtual ToasterNotify *qt_toasterNotify(); 62 | 63 | virtual MainPage *qt_page() const ; 64 | 65 | private: 66 | mutable p3EasyTransport *mEasyTransport ; 67 | mutable RsPluginHandler *mPlugInHandler; 68 | mutable RsPeers* mPeers; 69 | mutable ConfigPage *config_page ; 70 | mutable QIcon *mIcon; 71 | mutable MainPage* mainpage ; 72 | 73 | EasyTransportNotify *mEasyTransportNotify ; 74 | EasyTransportGUIHandler *mEasyTransportGUIHandler ; 75 | }; 76 | 77 | -------------------------------------------------------------------------------- /interface/rsEasyTransport.h: -------------------------------------------------------------------------------- 1 | /* this is a simple class to make it easy for any part of the plugin to call its services */ 2 | /**************************************************************** 3 | * RetroShare is distributed under the following license: 4 | * 5 | * Copyright (C) 2015 6 | * 7 | * This program is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU General Public License 9 | * as published by the Free Software Foundation; either version 2 10 | * of the License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 | * Boston, MA 02110-1301, USA. 21 | ****************************************************************/ 22 | 23 | // interface class for p3EasyTransport service 24 | // 25 | 26 | #pragma once 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include "gui/EasyTransportNotify.h" 34 | 35 | class RsEasyTransport ; 36 | extern RsEasyTransport *rsEasyTransport; 37 | 38 | static const uint32_t CONFIG_TYPE_EasyTransport_PLUGIN = 0xe001 ; 39 | 40 | class RsEasyTransportPongResult 41 | { 42 | public: 43 | RsEasyTransportPongResult() 44 | :mTS(0), mRTT(0), mOffset(0) { return; } 45 | 46 | RsEasyTransportPongResult(double ts, double rtt, double offset) 47 | :mTS(ts), mRTT(rtt), mOffset(offset) { return; } 48 | 49 | double mTS; 50 | double mRTT; 51 | double mOffset; 52 | }; 53 | 54 | struct RsEasyTransportDataChunk 55 | { 56 | typedef enum { RS_EasyTransport_DATA_TYPE_AUDIO, RS_EasyTransport_DATA_TYPE_VIDEO } RsEasyTransportDataType ; 57 | 58 | void *data ; // create/delete using malloc/free. 59 | uint32_t size ; 60 | RsEasyTransportDataType type ; // video or audio 61 | }; 62 | 63 | class RsEasyTransport 64 | { 65 | public: 66 | virtual int sendEasyTransportHangUpCall(const RsPeerId& peer_id) = 0; 67 | virtual int sendEasyTransportRinging(const RsPeerId& peer_id) = 0; 68 | virtual int sendEasyTransportAcceptCall(const RsPeerId& peer_id) = 0; 69 | 70 | virtual void ping_all() = 0; 71 | virtual void broadcast_paint(int x, int y) = 0; 72 | virtual void msg_peer(std::string msg, RsPeerId peerId) = 0; 73 | virtual void msg_all(std::string msg) = 0; 74 | EasyTransportNotify *mNotify =0 ; 75 | // Sending data. The client keeps the memory ownership and must delete it after calling this. 76 | virtual int sendEasyTransportData(const RsPeerId& peer_id,const RsEasyTransportDataChunk& chunk) = 0; 77 | 78 | // The server fill in the data and gives up memory ownership. The client must delete the memory 79 | // in each chunk once it has been used. 80 | // 81 | virtual bool getIncomingData(const RsPeerId& peer_id,std::vector& chunks) = 0; 82 | 83 | typedef enum { AudioTransmitContinous = 0, AudioTransmitVAD = 1, AudioTransmitPushToTalk = 2 } enumAudioTransmit ; 84 | 85 | // Config stuff 86 | 87 | virtual uint32_t getPongResults(const RsPeerId& id, int n, std::list &results) = 0; 88 | }; 89 | 90 | 91 | -------------------------------------------------------------------------------- /services/p3EasyTransport.h: -------------------------------------------------------------------------------- 1 | /* this handles the networking service of this plugin */ 2 | /**************************************************************** 3 | * RetroShare is distributed under the following license: 4 | * 5 | * Copyright (C) 2015 6 | * 7 | * This program is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU General Public License 9 | * as published by the Free Software Foundation; either version 2 10 | * of the License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 | * Boston, MA 02110-1301, USA. 21 | ****************************************************************/ 22 | 23 | #pragma once 24 | 25 | #include 26 | #include 27 | 28 | #include "services/rsEasyTransportItems.h" 29 | #include "services/p3service.h" 30 | #include "serialiser/rstlvbase.h" 31 | #include "serialiser/rsconfigitems.h" 32 | #include "plugins/rspqiservice.h" 33 | #include 34 | 35 | class p3LinkMgr; 36 | class EasyTransportNotify ; 37 | 38 | class EasyTransportPeerInfo 39 | { 40 | public: 41 | 42 | bool initialisePeerInfo(const RsPeerId &id); 43 | 44 | RsPeerId mId; 45 | double mCurrentPingTS; 46 | double mCurrentPingCounter; 47 | bool mCurrentPongRecvd; 48 | 49 | uint32_t mLostPongs; 50 | uint32_t mSentPings; 51 | uint32_t total_bytes_received ; 52 | uint32_t average_incoming_bandwidth ; 53 | 54 | std::list mPongResults; 55 | std::list incoming_queue ; 56 | }; 57 | 58 | 59 | //!The RS VoIP Test service. 60 | /** 61 | * 62 | * This is only used to test Latency for the moment. 63 | */ 64 | 65 | class p3EasyTransport: public RsPQIService, public RsEasyTransport 66 | // Maybe we inherit from these later - but not needed for now. 67 | //, public p3Config, public pqiMonitor 68 | { 69 | public: 70 | p3EasyTransport(RsPluginHandler *cm,EasyTransportNotify *); 71 | 72 | /***** overloaded from rsEasyTransport *****/ 73 | 74 | virtual uint32_t getPongResults(const RsPeerId &id, int n, std::list &results); 75 | 76 | // Call stuff. 77 | // 78 | 79 | // Sending data. The client keeps the memory ownership and must delete it after calling this. 80 | virtual int sendEasyTransportData(const RsPeerId &peer_id,const RsEasyTransportDataChunk& chunk) ; 81 | 82 | // The server fill in the data and gives up memory ownership. The client must delete the memory 83 | // in each chunk once it has been used. 84 | // 85 | virtual bool getIncomingData(const RsPeerId& peer_id,std::vector& chunks) ; 86 | 87 | virtual int sendEasyTransportHangUpCall(const RsPeerId& peer_id) ; 88 | virtual int sendEasyTransportRinging(const RsPeerId& peer_id) ; 89 | virtual int sendEasyTransportAcceptCall(const RsPeerId &peer_id) ; 90 | 91 | /***** overloaded from p3Service *****/ 92 | /*! 93 | * This retrieves all chat msg items and also (important!) 94 | * processes chat-status items that are in service item queue. chat msg item requests are also processed and not returned 95 | * (important! also) notifications sent to notify base on receipt avatar, immediate status and custom status 96 | * : notifyCustomState, notifyChatStatus, notifyPeerHasNewAvatar 97 | * @see NotifyBase 98 | */ 99 | virtual int tick(); 100 | virtual int status(); 101 | virtual bool recvItem(RsItem *item); 102 | 103 | /*************** pqiMonitor callback ***********************/ 104 | //virtual void statusChange(const std::list &plist); 105 | 106 | 107 | /************* from p3Config *******************/ 108 | virtual RsSerialiser *setupSerialiser() ; 109 | 110 | /*! 111 | * chat msg items and custom status are saved 112 | */ 113 | virtual bool saveList(bool& cleanup, std::list&) ; 114 | virtual bool loadList(std::list& load) ; 115 | virtual std::string configurationFileName() const { return "net_example.cfg" ; } 116 | 117 | virtual RsServiceInfo getServiceInfo() ; 118 | 119 | void ping_all(); 120 | 121 | void broadcast_paint(int x, int y); 122 | void msg_all(std::string msg); 123 | void msg_peer(std::string msg, RsPeerId peerId); 124 | private: 125 | int sendPackets(); 126 | void sendPingMeasurements(); 127 | void sendBandwidthInfo(); 128 | 129 | int sendEasyTransportBandwidth(const RsPeerId &peer_id,uint32_t bytes_per_sec) ; 130 | 131 | int handlePing(RsEasyTransportPingItem *item); 132 | int handlePong(RsEasyTransportPongItem *item); 133 | 134 | int storePingAttempt(const RsPeerId &id, double ts, uint32_t mCounter); 135 | int storePongResult(const RsPeerId& id, uint32_t counter, double ts, double rtt, double offset); 136 | 137 | void handleProtocol(RsEasyTransportProtocolItem*) ; 138 | void handlePaint(RsEasyTransportPaintItem *item); 139 | void handleData(RsEasyTransportDataItem*) ; 140 | 141 | RsMutex mEasyTransportMtx; 142 | 143 | EasyTransportPeerInfo *locked_GetPeerInfo(const RsPeerId& id); 144 | 145 | static RsTlvKeyValue push_int_value(const std::string& key,int value) ; 146 | static int pop_int_value(const std::string& s) ; 147 | 148 | std::map mPeerInfo; 149 | time_t mSentPingTime; 150 | time_t mSentBandwidthInfoTime; 151 | uint32_t mCounter; 152 | 153 | RsServiceControl *mServiceControl; 154 | EasyTransportNotify *mNotify ; 155 | 156 | int _atransmit ; 157 | int _voice_hold ; 158 | int _vadmin ; 159 | int _vadmax ; 160 | int _min_loudness ; 161 | int _noise_suppress ; 162 | bool _echo_cancel ; 163 | }; 164 | -------------------------------------------------------------------------------- /EasyTransportPlugin.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************** 2 | * RetroShare is distributed under the following license: 3 | * 4 | * Copyright (C) 2015 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301, USA. 20 | ****************************************************************/ 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include "EasyTransportPlugin.h" 31 | #include "interface/rsEasyTransport.h" 32 | #include "gui/NEMainpage.h" 33 | #include "gui/EasyTransportNotify.h" 34 | 35 | 36 | #define IMAGE_EasyTransport ":/images/talking_on.svg" 37 | 38 | static void *inited = new EasyTransportPlugin() ; 39 | 40 | extern "C" { 41 | 42 | // This is *the* functions required by RS plugin system to give RS access to the plugin. 43 | // Be careful to: 44 | // - always respect the C linkage convention 45 | // - always return an object of type RsPlugin* 46 | // 47 | void *RETROSHARE_PLUGIN_provide() 48 | { 49 | static EasyTransportPlugin *p = new EasyTransportPlugin() ; 50 | 51 | return (void*)p ; 52 | } 53 | 54 | // This symbol contains the svn revision number grabbed from the executable. 55 | // It will be tested by RS to load the plugin automatically, since it is safe to load plugins 56 | // with same revision numbers, assuming that the revision numbers are up-to-date. 57 | // 58 | uint32_t RETROSHARE_PLUGIN_revision = RS_REVISION_NUMBER ; 59 | 60 | // This symbol contains the svn revision number grabbed from the executable. 61 | // It will be tested by RS to load the plugin automatically, since it is safe to load plugins 62 | // with same revision numbers, assuming that the revision numbers are up-to-date. 63 | // 64 | uint32_t RETROSHARE_PLUGIN_api = RS_PLUGIN_API_VERSION ; 65 | } 66 | 67 | void EasyTransportPlugin::getPluginVersion(int& major, int& minor, int& build, int& svn_rev) const 68 | { 69 | major = RS_MAJOR_VERSION ; 70 | minor = RS_MINOR_VERSION ; 71 | build = RS_BUILD_NUMBER ; 72 | svn_rev = RS_REVISION_NUMBER ; 73 | } 74 | 75 | EasyTransportPlugin::EasyTransportPlugin() 76 | { 77 | qRegisterMetaType("RsPeerId"); 78 | mainpage = NULL ; 79 | mEasyTransport = NULL ; 80 | mPlugInHandler = NULL; 81 | mPeers = NULL; 82 | config_page = NULL ; 83 | mIcon = NULL ; 84 | 85 | mEasyTransportNotify = new EasyTransportNotify; 86 | } 87 | 88 | void EasyTransportPlugin::setInterfaces(RsPlugInInterfaces &interfaces) 89 | { 90 | mPeers = interfaces.mPeers; 91 | } 92 | 93 | /*ConfigPage *EasyTransportPlugin::qt_config_page() const 94 | { 95 | // The config pages are deleted when config is closed, so it's important not to static the 96 | // created object. 97 | // 98 | return new AudioInputConfig() ; 99 | }*/ 100 | 101 | QDialog *EasyTransportPlugin::qt_about_page() const 102 | { 103 | static QMessageBox *about_dialog = NULL ; 104 | 105 | if(about_dialog == NULL) 106 | { 107 | about_dialog = new QMessageBox() ; 108 | 109 | QString text ; 110 | text += QObject::tr("

RetroShare EasyTransport plugin


* Contributors: Cyril Soler, Josselin Jacquard
") ; 111 | text += QObject::tr("
The EasyTransport plugin adds EasyTransport to the private chat window of RetroShare. to use it, proceed as follows:
    ") ; 112 | text += QObject::tr("
  • setup microphone levels using the configuration panel
  • ") ; 113 | text += QObject::tr("
  • check your microphone by looking at the VU-metters
  • ") ; 114 | text += QObject::tr("
  • in the private chat, enable sound input/output by clicking on the two EasyTransport icons
") ; 115 | text += QObject::tr("Your friend needs to run the plugin to talk/listen to you, or course.") ; 116 | text += QObject::tr("

This is an experimental feature. Don't hesitate to send comments and suggestion to the RS dev team.") ; 117 | 118 | about_dialog->setText(text) ; 119 | about_dialog->setStandardButtons(QMessageBox::Ok) ; 120 | } 121 | 122 | return about_dialog ; 123 | } 124 | 125 | /*ChatWidgetHolder *EasyTransportPlugin::qt_get_chat_widget_holder(ChatWidget *chatWidget) const 126 | { 127 | switch (chatWidget->chatType()) { 128 | case ChatWidget::CHATTYPE_PRIVATE: 129 | return new EasyTransportChatWidgetHolder(chatWidget, mEasyTransportNotify); 130 | case ChatWidget::CHATTYPE_UNKNOWN: 131 | case ChatWidget::CHATTYPE_LOBBY: 132 | case ChatWidget::CHATTYPE_DISTANT: 133 | break; 134 | } 135 | 136 | return NULL; 137 | }*/ 138 | 139 | p3Service *EasyTransportPlugin::p3_service() const 140 | { 141 | if(mEasyTransport == NULL) 142 | rsEasyTransport = mEasyTransport = new p3EasyTransport(mPlugInHandler,mEasyTransportNotify) ; // , 3600 * 24 * 30 * 6); // 6 Months 143 | 144 | return mEasyTransport ; 145 | } 146 | 147 | void EasyTransportPlugin::setPlugInHandler(RsPluginHandler *pgHandler) 148 | { 149 | mPlugInHandler = pgHandler; 150 | } 151 | 152 | QIcon *EasyTransportPlugin::qt_icon() const 153 | { 154 | if (mIcon == NULL) { 155 | Q_INIT_RESOURCE(EasyTransport_images); 156 | 157 | mIcon = new QIcon(IMAGE_EasyTransport); 158 | } 159 | 160 | return mIcon; 161 | } 162 | MainPage *EasyTransportPlugin::qt_page() const 163 | { 164 | if(mainpage == NULL){ 165 | mainpage = new NEMainpage(0, mEasyTransportNotify);//mPeers, mFiles) ; 166 | //tpage = new NEMainpage( ); 167 | //mainpage = tpage; 168 | } 169 | 170 | return mainpage ; 171 | } 172 | 173 | std::string EasyTransportPlugin::getShortPluginDescription() const 174 | { 175 | return "EasyTransport"; 176 | } 177 | 178 | std::string EasyTransportPlugin::getPluginName() const 179 | { 180 | return "EasyTransportPlugin"; 181 | } 182 | 183 | QTranslator* EasyTransportPlugin::qt_translator(QApplication */*app*/, const QString& languageCode, const QString& externalDir) const 184 | { 185 | return NULL; 186 | } 187 | 188 | void EasyTransportPlugin::qt_sound_events(SoundEvents &/*events*/) const 189 | { 190 | // events.addEvent(QApplication::translate("EasyTransport", "EasyTransport"), QApplication::translate("EasyTransport", "Incoming call"), EasyTransport_SOUND_INCOMING_CALL); 191 | } 192 | 193 | /*ToasterNotify *EasyTransportPlugin::qt_toasterNotify(){ 194 | if (!mEasyTransportToasterNotify) { 195 | mEasyTransportToasterNotify = new EasyTransportToasterNotify(mEasyTransport, mEasyTransportNotify); 196 | } 197 | return mEasyTransportToasterNotify; 198 | }*/ 199 | -------------------------------------------------------------------------------- /services/rsEasyTransportItems.h: -------------------------------------------------------------------------------- 1 | /* this describes the datatypes sent over the network, and how to (de)serialise them */ 2 | /**************************************************************** 3 | * RetroShare is distributed under the following license: 4 | * 5 | * Copyright (C) 2015 6 | * 7 | * This program is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU General Public License 9 | * as published by the Free Software Foundation; either version 2 10 | * of the License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 | * Boston, MA 02110-1301, USA. 21 | ****************************************************************/ 22 | 23 | #pragma once 24 | 25 | /* 26 | * libretroshare/src/serialiser: rsEasyTransportItems.h 27 | * 28 | * RetroShare Serialiser. 29 | * 30 | * Copyright 2011 by Robert Fernie. 31 | * 32 | * This library is free software; you can redistribute it and/or 33 | * modify it under the terms of the GNU Library General Public 34 | * License Version 2 as published by the Free Software Foundation. 35 | * 36 | * This library is distributed in the hope that it will be useful, 37 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 38 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 39 | * Library General Public License for more details. 40 | * 41 | * You should have received a copy of the GNU Library General Public 42 | * License along with this library; if not, write to the Free Software 43 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 44 | * USA. 45 | * 46 | * Please report all bugs and problems to "retroshare@lunamutt.com". 47 | * 48 | */ 49 | 50 | #include 51 | 52 | #include "serialiser/rsserviceids.h" 53 | #include "serialiser/rsserial.h" 54 | 55 | /**************************************************************************/ 56 | 57 | const uint16_t RS_SERVICE_TYPE_EasyTransport_PLUGIN = 0xb031; 58 | 59 | const uint8_t RS_PKT_SUBTYPE_EasyTransport_PING = 0x01; 60 | const uint8_t RS_PKT_SUBTYPE_EasyTransport_PONG = 0x02; 61 | const uint8_t RS_PKT_SUBTYPE_EasyTransport_PROTOCOL = 0x03 ;//unused! 62 | const uint8_t RS_PKT_SUBTYPE_EasyTransport_PAINT = 0x04 ; 63 | const uint8_t RS_PKT_SUBTYPE_EasyTransport_DATA = 0x05 ; 64 | 65 | const uint8_t QOS_PRIORITY_RS_EasyTransport = 9 ; 66 | 67 | const uint32_t RS_EasyTransport_FLAGS_VIDEO_DATA = 0x0001 ; 68 | const uint32_t RS_EasyTransport_FLAGS_AUDIO_DATA = 0x0002 ; 69 | 70 | class RsEasyTransportItem: public RsItem 71 | { 72 | public: 73 | RsEasyTransportItem(uint8_t net_example_subtype) 74 | : RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_EasyTransport_PLUGIN,net_example_subtype) 75 | { 76 | setPriorityLevel(QOS_PRIORITY_RS_EasyTransport) ; 77 | } 78 | 79 | virtual ~RsEasyTransportItem() {}; 80 | virtual void clear() {}; 81 | virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) = 0 ; 82 | 83 | virtual bool serialise(void *data,uint32_t& size) = 0 ; // Isn't it better that items can serialise themselves ? 84 | virtual uint32_t serial_size() const = 0 ; // deserialise is handled using a constructor 85 | }; 86 | 87 | class RsEasyTransportPingItem: public RsEasyTransportItem 88 | { 89 | public: 90 | RsEasyTransportPingItem() :RsEasyTransportItem(RS_PKT_SUBTYPE_EasyTransport_PING) {} 91 | RsEasyTransportPingItem(void *data,uint32_t size) ; 92 | 93 | virtual bool serialise(void *data,uint32_t& size) ; 94 | virtual uint32_t serial_size() const ; 95 | 96 | virtual ~RsEasyTransportPingItem() {} 97 | virtual std::ostream& print(std::ostream &out, uint16_t indent = 0); 98 | 99 | uint32_t mSeqNo; 100 | uint64_t mPingTS; 101 | }; 102 | 103 | class RsEasyTransportPongItem: public RsEasyTransportItem 104 | { 105 | public: 106 | RsEasyTransportPongItem() :RsEasyTransportItem(RS_PKT_SUBTYPE_EasyTransport_PONG) {} 107 | RsEasyTransportPongItem(void *data,uint32_t size) ; 108 | 109 | virtual bool serialise(void *data,uint32_t& size) ; 110 | virtual uint32_t serial_size() const ; 111 | 112 | virtual ~RsEasyTransportPongItem() {} 113 | virtual std::ostream& print(std::ostream &out, uint16_t indent = 0); 114 | 115 | uint32_t mSeqNo; 116 | uint64_t mPingTS; 117 | uint64_t mPongTS; 118 | }; 119 | 120 | class RsEasyTransportDataItem: public RsEasyTransportItem 121 | { 122 | public: 123 | RsEasyTransportDataItem() :RsEasyTransportItem(RS_PKT_SUBTYPE_EasyTransport_DATA) {} 124 | RsEasyTransportDataItem(void *data,uint32_t size) ; // de-serialization 125 | 126 | virtual bool serialise(void *data,uint32_t& size) ; 127 | virtual uint32_t serial_size() const ; 128 | 129 | virtual ~RsEasyTransportDataItem() 130 | { 131 | //free(net_example_data) ; 132 | //net_example_data = NULL ; 133 | } 134 | virtual std::ostream& print(std::ostream &out, uint16_t indent = 0); 135 | 136 | uint32_t flags ; 137 | uint32_t data_size ; 138 | std::string m_msg; 139 | }; 140 | 141 | class RsEasyTransportPaintItem: public RsEasyTransportItem 142 | { 143 | public: 144 | RsEasyTransportPaintItem() :RsEasyTransportItem(RS_PKT_SUBTYPE_EasyTransport_PAINT) {} 145 | RsEasyTransportPaintItem(void *data,uint32_t size) ; 146 | 147 | enum { EasyTransportProtocol_Ring = 1, EasyTransportProtocol_Ackn = 2, EasyTransportProtocol_Close = 3, EasyTransportProtocol_Bandwidth = 4 } ; 148 | 149 | virtual bool serialise(void *data,uint32_t& size) ; 150 | virtual uint32_t serial_size() const ; 151 | 152 | virtual ~RsEasyTransportPaintItem() {} 153 | virtual std::ostream& print(std::ostream &out, uint16_t indent = 0); 154 | 155 | uint32_t x ; 156 | uint32_t y ; 157 | }; 158 | 159 | class RsEasyTransportProtocolItem: public RsEasyTransportItem 160 | { 161 | public: 162 | RsEasyTransportProtocolItem() :RsEasyTransportItem(RS_PKT_SUBTYPE_EasyTransport_PROTOCOL) {} 163 | RsEasyTransportProtocolItem(void *data,uint32_t size) ; 164 | 165 | enum { EasyTransportProtocol_Ring = 1, EasyTransportProtocol_Ackn = 2, EasyTransportProtocol_Close = 3, EasyTransportProtocol_Bandwidth = 4 } ; 166 | 167 | virtual bool serialise(void *data,uint32_t& size) ; 168 | virtual uint32_t serial_size() const ; 169 | 170 | virtual ~RsEasyTransportProtocolItem() {} 171 | virtual std::ostream& print(std::ostream &out, uint16_t indent = 0); 172 | 173 | uint32_t protocol ; 174 | uint32_t flags ; 175 | }; 176 | 177 | class RsEasyTransportSerialiser: public RsSerialType 178 | { 179 | public: 180 | RsEasyTransportSerialiser() 181 | :RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_EasyTransport_PLUGIN) 182 | { 183 | } 184 | virtual ~RsEasyTransportSerialiser() {} 185 | 186 | virtual uint32_t size (RsItem *item) 187 | { 188 | return dynamic_cast(item)->serial_size() ; 189 | } 190 | 191 | virtual bool serialise (RsItem *item, void *data, uint32_t *size) 192 | { 193 | return dynamic_cast(item)->serialise(data,*size) ; 194 | } 195 | virtual RsItem *deserialise(void *data, uint32_t *size); 196 | }; 197 | 198 | /**************************************************************************/ 199 | -------------------------------------------------------------------------------- /services/rsEasyTransportItems.cc: -------------------------------------------------------------------------------- 1 | /**************************************************************** 2 | * RetroShare is distributed under the following license: 3 | * 4 | * Copyright (C) 2015 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301, USA. 20 | ****************************************************************/ 21 | 22 | #include 23 | #include "serialiser/rsbaseserial.h" 24 | #include "serialiser/rstlvbase.h" 25 | 26 | #include "services/rsEasyTransportItems.h" 27 | 28 | /*** 29 | #define RSSERIAL_DEBUG 1 30 | ***/ 31 | 32 | #include 33 | 34 | #define HOLLERITH_LEN_SPEC 4 35 | /*************************************************************************/ 36 | 37 | std::ostream& RsEasyTransportPingItem::print(std::ostream &out, uint16_t indent) 38 | { 39 | printRsItemBase(out, "RsEasyTransportPingItem", indent); 40 | uint16_t int_Indent = indent + 2; 41 | printIndent(out, int_Indent); 42 | out << "SeqNo: " << mSeqNo << std::endl; 43 | 44 | printIndent(out, int_Indent); 45 | out << "PingTS: " << std::hex << mPingTS << std::dec << std::endl; 46 | 47 | printRsItemEnd(out, "RsEasyTransportPingItem", indent); 48 | return out; 49 | } 50 | 51 | std::ostream& RsEasyTransportPongItem::print(std::ostream &out, uint16_t indent) 52 | { 53 | printRsItemBase(out, "RsEasyTransportPongItem", indent); 54 | uint16_t int_Indent = indent + 2; 55 | printIndent(out, int_Indent); 56 | out << "SeqNo: " << mSeqNo << std::endl; 57 | 58 | printIndent(out, int_Indent); 59 | out << "PingTS: " << std::hex << mPingTS << std::dec << std::endl; 60 | 61 | printIndent(out, int_Indent); 62 | out << "PongTS: " << std::hex << mPongTS << std::dec << std::endl; 63 | 64 | printRsItemEnd(out, "RsEasyTransportPongItem", indent); 65 | return out; 66 | } 67 | std::ostream& RsEasyTransportProtocolItem::print(std::ostream &out, uint16_t indent) 68 | { 69 | printRsItemBase(out, "RsEasyTransportProtocolItem", indent); 70 | uint16_t int_Indent = indent + 2; 71 | printIndent(out, int_Indent); 72 | out << "flags: " << flags << std::endl; 73 | 74 | printIndent(out, int_Indent); 75 | out << "protocol: " << std::hex << protocol << std::dec << std::endl; 76 | 77 | printRsItemEnd(out, "RsEasyTransportProtocolItem", indent); 78 | return out; 79 | } 80 | std::ostream& RsEasyTransportPaintItem::print(std::ostream &out, uint16_t indent) 81 | { 82 | printRsItemBase(out, "RsEasyTransportPaintItem", indent); 83 | uint16_t int_Indent = indent + 2; 84 | printIndent(out, int_Indent); 85 | out << "x: " << x << std::endl; 86 | 87 | printIndent(out, int_Indent); 88 | out << "y: " << y << std::endl; 89 | 90 | printRsItemEnd(out, "RsEasyTransportPaintItem", indent); 91 | return out; 92 | } 93 | std::ostream& RsEasyTransportDataItem::print(std::ostream &out, uint16_t indent) 94 | { 95 | printRsItemBase(out, "RsEasyTransportDataItem", indent); 96 | uint16_t int_Indent = indent + 2; 97 | printIndent(out, int_Indent); 98 | out << "flags: " << flags << std::endl; 99 | 100 | printIndent(out, int_Indent); 101 | out << "data size: " << std::hex << data_size << std::dec << std::endl; 102 | 103 | printRsItemEnd(out, "RsEasyTransportDataItem", indent); 104 | return out; 105 | } 106 | 107 | /*************************************************************************/ 108 | uint32_t RsEasyTransportDataItem::serial_size() const 109 | { 110 | uint32_t s = 8; /* header */ 111 | s += 4; /* flags */ 112 | s += 4; /* data_size */ 113 | //s += m_msg.length()+HOLLERITH_LEN_SPEC; /* data */ 114 | s += getRawStringSize(m_msg); 115 | 116 | return s; 117 | } 118 | uint32_t RsEasyTransportProtocolItem::serial_size() const 119 | { 120 | uint32_t s = 8; /* header */ 121 | s += 4; /* flags */ 122 | s += 4; /* protocol */ 123 | 124 | return s; 125 | } 126 | uint32_t RsEasyTransportPaintItem::serial_size() const 127 | { 128 | uint32_t s = 8; /* header */ 129 | s += 4; /* x */ 130 | s += 4; /* y */ 131 | 132 | return s; 133 | } 134 | uint32_t RsEasyTransportPingItem::serial_size() const 135 | { 136 | uint32_t s = 8; /* header */ 137 | s += 4; /* seqno */ 138 | s += 8; /* pingTS */ 139 | 140 | return s; 141 | } 142 | bool RsEasyTransportProtocolItem::serialise(void *data, uint32_t& pktsize) 143 | { 144 | uint32_t tlvsize = serial_size() ; 145 | uint32_t offset = 0; 146 | 147 | if (pktsize < tlvsize) 148 | return false; /* not enough space */ 149 | 150 | pktsize = tlvsize; 151 | 152 | bool ok = true; 153 | 154 | ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); 155 | 156 | #ifdef RSSERIAL_DEBUG 157 | std::cerr << "RsEasyTransportSerialiser::serialiseEasyTransportDataItem() Header: " << ok << std::endl; 158 | std::cerr << "RsEasyTransportSerialiser::serialiseEasyTransportDataItem() Size: " << tlvsize << std::endl; 159 | #endif 160 | 161 | /* skip the header */ 162 | offset += 8; 163 | 164 | /* add mandatory parts first */ 165 | ok &= setRawUInt32(data, tlvsize, &offset, protocol); 166 | ok &= setRawUInt32(data, tlvsize, &offset, flags); 167 | 168 | if (offset != tlvsize) 169 | { 170 | ok = false; 171 | std::cerr << "RsEasyTransportSerialiser::serialiseEasyTransportPingItem() Size Error! " << std::endl; 172 | } 173 | 174 | return ok; 175 | } 176 | bool RsEasyTransportPaintItem::serialise(void *data, uint32_t& pktsize) 177 | { 178 | uint32_t tlvsize = serial_size() ; 179 | uint32_t offset = 0; 180 | 181 | if (pktsize < tlvsize) 182 | return false; /* not enough space */ 183 | 184 | pktsize = tlvsize; 185 | 186 | bool ok = true; 187 | 188 | ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); 189 | 190 | #ifdef RSSERIAL_DEBUG 191 | std::cerr << "RsEasyTransportSerialiser::serialiseEasyTransportDataItem() Header: " << ok << std::endl; 192 | std::cerr << "RsEasyTransportSerialiser::serialiseEasyTransportDataItem() Size: " << tlvsize << std::endl; 193 | #endif 194 | 195 | /* skip the header */ 196 | offset += 8; 197 | 198 | /* add mandatory parts first */ 199 | ok &= setRawUInt32(data, tlvsize, &offset, x); 200 | ok &= setRawUInt32(data, tlvsize, &offset, y); 201 | 202 | if (offset != tlvsize) 203 | { 204 | ok = false; 205 | std::cerr << "RsEasyTransportSerialiser::serialiseEasyTransportPingItem() Size Error! " << std::endl; 206 | } 207 | 208 | return ok; 209 | } 210 | /* serialise the data to the buffer */ 211 | bool RsEasyTransportDataItem::serialise(void *data, uint32_t& pktsize) 212 | { 213 | uint32_t tlvsize = serial_size() ; 214 | uint32_t offset = 0; 215 | 216 | if (pktsize < tlvsize) 217 | return false; /* not enough space */ 218 | 219 | pktsize = tlvsize; 220 | 221 | bool ok = true; 222 | 223 | ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); 224 | 225 | #ifdef RSSERIAL_DEBUG 226 | std::cerr << "RsEasyTransportSerialiser::serialiseEasyTransportDataItem() Header: " << ok << std::endl; 227 | std::cerr << "RsEasyTransportSerialiser::serialiseEasyTransportDataItem() Size: " << tlvsize << std::endl; 228 | #endif 229 | 230 | /* skip the header */ 231 | offset += 8; 232 | 233 | /* add mandatory parts first */ 234 | ok &= setRawUInt32(data, tlvsize, &offset, flags); 235 | ok &= setRawUInt32(data, tlvsize, &offset, data_size); 236 | 237 | 238 | ok &= setRawString(data, tlvsize, &offset, m_msg ); 239 | std::cout << "string sizes: " << getRawStringSize(m_msg) << " OR " << m_msg.size() << "\n"; 240 | //offset += m_msg.size() ; 241 | //offset += getRawStringSize(m_msg); 242 | //memcpy( &((uint8_t*)data)[offset],net_example_data,data_size) ; 243 | //offset += data_size ; 244 | 245 | if (offset != tlvsize) 246 | { 247 | ok = false; 248 | std::cerr << "RsEasyTransportSerialiser::serialiseEasyTransportPingItem() Size Error! " << std::endl; 249 | std::cerr << "expected " << tlvsize << " got " << offset << std::endl; 250 | std::cerr << "m_msg looks like " << m_msg << std::endl; 251 | } 252 | 253 | return ok; 254 | } 255 | /* serialise the data to the buffer */ 256 | bool RsEasyTransportPingItem::serialise(void *data, uint32_t& pktsize) 257 | { 258 | uint32_t tlvsize = serial_size() ; 259 | uint32_t offset = 0; 260 | 261 | if (pktsize < tlvsize) 262 | return false; /* not enough space */ 263 | 264 | pktsize = tlvsize; 265 | 266 | bool ok = true; 267 | 268 | ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); 269 | 270 | #ifdef RSSERIAL_DEBUG 271 | std::cerr << "RsEasyTransportSerialiser::serialiseEasyTransportPingItem() Header: " << ok << std::endl; 272 | std::cerr << "RsEasyTransportSerialiser::serialiseEasyTransportPingItem() Size: " << tlvsize << std::endl; 273 | #endif 274 | 275 | /* skip the header */ 276 | offset += 8; 277 | 278 | /* add mandatory parts first */ 279 | ok &= setRawUInt32(data, tlvsize, &offset, mSeqNo); 280 | ok &= setRawUInt64(data, tlvsize, &offset, mPingTS); 281 | 282 | if (offset != tlvsize) 283 | { 284 | ok = false; 285 | std::cerr << "RsEasyTransportSerialiser::serialiseEasyTransportPingItem() Size Error! " << std::endl; 286 | } 287 | 288 | return ok; 289 | } 290 | 291 | RsEasyTransportProtocolItem::RsEasyTransportProtocolItem(void *data, uint32_t pktsize) 292 | : RsEasyTransportItem(RS_PKT_SUBTYPE_EasyTransport_PROTOCOL) 293 | { 294 | /* get the type and size */ 295 | uint32_t rstype = getRsItemId(data); 296 | uint32_t rssize = getRsItemSize(data); 297 | 298 | uint32_t offset = 0; 299 | 300 | if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_EasyTransport_PLUGIN != getRsItemService(rstype)) || (RS_PKT_SUBTYPE_EasyTransport_PROTOCOL != getRsItemSubType(rstype))) 301 | throw std::runtime_error("Wrong packet type!") ; 302 | 303 | if (pktsize < rssize) /* check size */ 304 | throw std::runtime_error("Not enough size!") ; 305 | 306 | bool ok = true; 307 | 308 | /* skip the header */ 309 | offset += 8; 310 | 311 | /* get mandatory parts first */ 312 | ok &= getRawUInt32(data, rssize, &offset, &protocol); 313 | ok &= getRawUInt32(data, rssize, &offset, &flags); 314 | 315 | if (offset != rssize) 316 | throw std::runtime_error("Deserialisation error!") ; 317 | 318 | if (!ok) 319 | throw std::runtime_error("Deserialisation error!") ; 320 | } 321 | RsEasyTransportPaintItem::RsEasyTransportPaintItem(void *data, uint32_t pktsize) 322 | : RsEasyTransportItem(RS_PKT_SUBTYPE_EasyTransport_PAINT) 323 | { 324 | /* get the type and size */ 325 | uint32_t rstype = getRsItemId(data); 326 | uint32_t rssize = getRsItemSize(data); 327 | 328 | uint32_t offset = 0; 329 | 330 | if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_EasyTransport_PLUGIN != getRsItemService(rstype)) || (RS_PKT_SUBTYPE_EasyTransport_PAINT != getRsItemSubType(rstype))) 331 | throw std::runtime_error("Wrong packet type!") ; 332 | 333 | if (pktsize < rssize) /* check size */ 334 | throw std::runtime_error("Not enough size!") ; 335 | 336 | bool ok = true; 337 | 338 | /* skip the header */ 339 | offset += 8; 340 | 341 | /* get mandatory parts first */ 342 | ok &= getRawUInt32(data, rssize, &offset, &x); 343 | ok &= getRawUInt32(data, rssize, &offset, &y); 344 | 345 | if (offset != rssize) 346 | throw std::runtime_error("Deserialisation error!") ; 347 | 348 | if (!ok) 349 | throw std::runtime_error("Deserialisation error!") ; 350 | } 351 | RsEasyTransportPingItem::RsEasyTransportPingItem(void *data, uint32_t pktsize) 352 | : RsEasyTransportItem(RS_PKT_SUBTYPE_EasyTransport_PING) 353 | { 354 | /* get the type and size */ 355 | uint32_t rstype = getRsItemId(data); 356 | uint32_t rssize = getRsItemSize(data); 357 | 358 | uint32_t offset = 0; 359 | 360 | 361 | if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_EasyTransport_PLUGIN != getRsItemService(rstype)) || (RS_PKT_SUBTYPE_EasyTransport_PING != getRsItemSubType(rstype))) 362 | throw std::runtime_error("Wrong packet type!") ; 363 | 364 | if (pktsize < rssize) /* check size */ 365 | throw std::runtime_error("Not enough size!") ; 366 | 367 | bool ok = true; 368 | 369 | /* skip the header */ 370 | offset += 8; 371 | 372 | /* get mandatory parts first */ 373 | ok &= getRawUInt32(data, rssize, &offset, &mSeqNo); 374 | ok &= getRawUInt64(data, rssize, &offset, &mPingTS); 375 | 376 | if (offset != rssize) 377 | throw std::runtime_error("Deserialisation error!") ; 378 | 379 | if (!ok) 380 | throw std::runtime_error("Deserialisation error!") ; 381 | } 382 | 383 | /*************************************************************************/ 384 | /*************************************************************************/ 385 | 386 | 387 | uint32_t RsEasyTransportPongItem::serial_size() const 388 | { 389 | uint32_t s = 8; /* header */ 390 | s += 4; /* seqno */ 391 | s += 8; /* pingTS */ 392 | s += 8; /* pongTS */ 393 | 394 | return s; 395 | } 396 | 397 | /* serialise the data to the buffer */ 398 | bool RsEasyTransportPongItem::serialise(void *data, uint32_t& pktsize) 399 | { 400 | uint32_t tlvsize = serial_size() ; 401 | uint32_t offset = 0; 402 | 403 | if (pktsize < tlvsize) 404 | return false; /* not enough space */ 405 | 406 | pktsize = tlvsize; 407 | 408 | bool ok = true; 409 | 410 | ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); 411 | 412 | #ifdef RSSERIAL_DEBUG 413 | std::cerr << "RsEasyTransportSerialiser::serialiseEasyTransportPongItem() Header: " << ok << std::endl; 414 | std::cerr << "RsEasyTransportSerialiser::serialiseEasyTransportPongItem() Size: " << tlvsize << std::endl; 415 | #endif 416 | 417 | /* skip the header */ 418 | offset += 8; 419 | 420 | /* add mandatory parts first */ 421 | ok &= setRawUInt32(data, tlvsize, &offset, mSeqNo); 422 | ok &= setRawUInt64(data, tlvsize, &offset, mPingTS); 423 | ok &= setRawUInt64(data, tlvsize, &offset, mPongTS); 424 | 425 | if (offset != tlvsize) 426 | { 427 | ok = false; 428 | std::cerr << "RsEasyTransportSerialiser::serialiseEasyTransportPongItem() Size Error! " << std::endl; 429 | } 430 | 431 | return ok; 432 | } 433 | RsEasyTransportDataItem::RsEasyTransportDataItem(void *data, uint32_t pktsize) 434 | : RsEasyTransportItem(RS_PKT_SUBTYPE_EasyTransport_DATA) 435 | { 436 | /* get the type and size */ 437 | uint32_t rstype = getRsItemId(data); 438 | uint32_t rssize = getRsItemSize(data); 439 | 440 | uint32_t offset = 0; 441 | 442 | if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_EasyTransport_PLUGIN != getRsItemService(rstype)) || (RS_PKT_SUBTYPE_EasyTransport_DATA != getRsItemSubType(rstype))) 443 | throw std::runtime_error("Wrong packet subtype") ; 444 | 445 | if (pktsize < rssize) /* check size */ 446 | throw std::runtime_error("Not enough space") ; 447 | 448 | bool ok = true; 449 | 450 | /* skip the header */ 451 | offset += 8; 452 | 453 | /* get mandatory parts first */ 454 | ok &= getRawUInt32(data, rssize, &offset, &flags); 455 | ok &= getRawUInt32(data, rssize, &offset, &data_size); 456 | 457 | 458 | ok &= getRawString(data, rssize, &offset, m_msg ); 459 | 460 | /*net_example_data = malloc(data_size) ; 461 | memcpy(net_example_data,&((uint8_t*)data)[offset],data_size) ; 462 | offset += data_size ;*/ 463 | 464 | if (offset != rssize) 465 | throw std::runtime_error("Serialization error.") ; 466 | 467 | if (!ok) 468 | throw std::runtime_error("Serialization error.") ; 469 | } 470 | RsEasyTransportPongItem::RsEasyTransportPongItem(void *data, uint32_t pktsize) 471 | : RsEasyTransportItem(RS_PKT_SUBTYPE_EasyTransport_PONG) 472 | { 473 | /* get the type and size */ 474 | uint32_t rstype = getRsItemId(data); 475 | uint32_t rssize = getRsItemSize(data); 476 | 477 | uint32_t offset = 0; 478 | 479 | if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_EasyTransport_PLUGIN != getRsItemService(rstype)) || (RS_PKT_SUBTYPE_EasyTransport_PONG != getRsItemSubType(rstype))) 480 | throw std::runtime_error("Wrong packet subtype") ; 481 | 482 | if (pktsize < rssize) /* check size */ 483 | throw std::runtime_error("Not enough space") ; 484 | 485 | bool ok = true; 486 | 487 | /* skip the header */ 488 | offset += 8; 489 | 490 | /* get mandatory parts first */ 491 | ok &= getRawUInt32(data, rssize, &offset, &mSeqNo); 492 | ok &= getRawUInt64(data, rssize, &offset, &mPingTS); 493 | ok &= getRawUInt64(data, rssize, &offset, &mPongTS); 494 | 495 | if (offset != rssize) 496 | throw std::runtime_error("Serialization error.") ; 497 | 498 | if (!ok) 499 | throw std::runtime_error("Serialization error.") ; 500 | } 501 | 502 | /*************************************************************************/ 503 | 504 | RsItem* RsEasyTransportSerialiser::deserialise(void *data, uint32_t *pktsize) 505 | { 506 | #ifdef RSSERIAL_DEBUG 507 | std::cerr << "RsEasyTransportSerialiser::deserialise()" << std::endl; 508 | #endif 509 | 510 | /* get the type and size */ 511 | uint32_t rstype = getRsItemId(data); 512 | 513 | if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_EasyTransport_PLUGIN != getRsItemService(rstype))) 514 | return NULL ; 515 | 516 | try 517 | { 518 | switch(getRsItemSubType(rstype)) 519 | { 520 | case RS_PKT_SUBTYPE_EasyTransport_PING: return new RsEasyTransportPingItem(data, *pktsize); 521 | case RS_PKT_SUBTYPE_EasyTransport_PONG: return new RsEasyTransportPongItem(data, *pktsize); 522 | case RS_PKT_SUBTYPE_EasyTransport_PROTOCOL: return new RsEasyTransportProtocolItem(data, *pktsize); 523 | case RS_PKT_SUBTYPE_EasyTransport_PAINT: return new RsEasyTransportPaintItem(data, *pktsize); 524 | case RS_PKT_SUBTYPE_EasyTransport_DATA: return new RsEasyTransportDataItem(data, *pktsize); 525 | 526 | default: 527 | return NULL; 528 | } 529 | } 530 | catch(std::exception& e) 531 | { 532 | std::cerr << "RsEasyTransportSerialiser: deserialization error: " << e.what() << std::endl; 533 | return NULL; 534 | } 535 | } 536 | 537 | 538 | /*************************************************************************/ 539 | 540 | -------------------------------------------------------------------------------- /gui/images/self_undeafened.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 21 | deafened_self 23 | 25 | 28 | 32 | 36 | 37 | 40 | 44 | 48 | 49 | 51 | 55 | 59 | 60 | 62 | 66 | 70 | 74 | 78 | 79 | 81 | 85 | 89 | 90 | 93 | 97 | 101 | 102 | 105 | 109 | 113 | 114 | 117 | 121 | 125 | 126 | 130 | 137 | 144 | 151 | 158 | 165 | 172 | 179 | 190 | 197 | 208 | 215 | 226 | 233 | 243 | 250 | 261 | 264 | 268 | 272 | 273 | 280 | 287 | 294 | 303 | 306 | 310 | 314 | 315 | 325 | 332 | 339 | 349 | 351 | 355 | 359 | 363 | 367 | 368 | 379 | 389 | 390 | 410 | 412 | 413 | 415 | image/svg+xml 416 | 418 | deafened_self 419 | 421 | 2009.08.17 422 | 423 | 424 | Martin Skilnand 425 | 426 | 427 | 428 | 429 | Martin Skilnand 430 | 431 | 432 | 433 | 434 | Mumble team 435 | 436 | 437 | 438 | 439 | mumble deafened self 440 | 441 | 442 | Icon for voice chat program mumble 443 | deafened_self.svg 444 | git://mumble.git.sourceforge.net/gitroot/mumble 445 | 446 | 447 | 448 | 454 | 464 | 469 | 474 | 484 | 489 | 499 | 509 | 519 | 524 | 534 | 544 | 550 | 560 | 561 | 562 | -------------------------------------------------------------------------------- /gui/images/deafened_self.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 21 | deafened_self 23 | 25 | 28 | 32 | 36 | 37 | 40 | 44 | 48 | 49 | 51 | 55 | 59 | 60 | 62 | 66 | 70 | 74 | 78 | 79 | 81 | 85 | 89 | 90 | 93 | 97 | 101 | 102 | 105 | 109 | 113 | 114 | 117 | 121 | 125 | 126 | 130 | 137 | 144 | 151 | 158 | 165 | 172 | 179 | 190 | 197 | 208 | 215 | 226 | 233 | 243 | 250 | 261 | 264 | 268 | 272 | 273 | 280 | 287 | 294 | 303 | 306 | 310 | 314 | 315 | 325 | 332 | 339 | 349 | 351 | 355 | 359 | 363 | 367 | 368 | 379 | 389 | 390 | 410 | 412 | 413 | 415 | image/svg+xml 416 | 418 | deafened_self 419 | 421 | 2009.08.17 422 | 423 | 424 | Martin Skilnand 425 | 426 | 427 | 428 | 429 | Martin Skilnand 430 | 431 | 432 | 433 | 434 | Mumble team 435 | 436 | 437 | 438 | 439 | mumble deafened self 440 | 441 | 442 | Icon for voice chat program mumble 443 | deafened_self.svg 444 | git://mumble.git.sourceforge.net/gitroot/mumble 445 | 446 | 447 | 448 | 454 | 464 | 469 | 474 | 484 | 489 | 499 | 509 | 519 | 524 | 534 | 544 | 550 | 560 | 561 | 568 | 572 | 573 | 574 | -------------------------------------------------------------------------------- /services/p3EasyTransport.cc: -------------------------------------------------------------------------------- 1 | /**************************************************************** 2 | * RetroShare is distributed under the following license: 3 | * 4 | * Copyright (C) 2015 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 | * Boston, MA 02110-1301, USA. 20 | ****************************************************************/ 21 | 22 | #include "util/rsdir.h" 23 | #include "retroshare/rsiface.h" 24 | #include "pqi/pqibin.h" 25 | #include "pqi/pqistore.h" 26 | #include "pqi/p3linkmgr.h" 27 | #include 28 | #include 29 | 30 | #include // for std::istringstream 31 | 32 | #include "services/p3EasyTransport.h" 33 | #include "services/rsEasyTransportItems.h" 34 | 35 | #include 36 | 37 | #include "gui/EasyTransportNotify.h" 38 | 39 | 40 | //#define DEBUG_EasyTransport 1 41 | 42 | 43 | /* DEFINE INTERFACE POINTER! */ 44 | RsEasyTransport *rsEasyTransport = NULL; 45 | 46 | 47 | #define MAX_PONG_RESULTS 150 48 | #define EasyTransport_PING_PERIOD 10 49 | #define EasyTransport_BANDWIDTH_PERIOD 5 50 | 51 | 52 | #ifdef WINDOWS_SYS 53 | #include 54 | #include 55 | #endif 56 | 57 | static double getCurrentTS() 58 | { 59 | 60 | #ifndef WINDOWS_SYS 61 | struct timeval cts_tmp; 62 | gettimeofday(&cts_tmp, NULL); 63 | double cts = (cts_tmp.tv_sec) + ((double) cts_tmp.tv_usec) / 1000000.0; 64 | #else 65 | struct _timeb timebuf; 66 | _ftime( &timebuf); 67 | double cts = (timebuf.time) + ((double) timebuf.millitm) / 1000.0; 68 | #endif 69 | return cts; 70 | } 71 | 72 | static uint64_t convertTsTo64bits(double ts) 73 | { 74 | uint32_t secs = (uint32_t) ts; 75 | uint32_t usecs = (uint32_t) ((ts - (double) secs) * 1000000); 76 | uint64_t bits = (((uint64_t) secs) << 32) + usecs; 77 | return bits; 78 | } 79 | 80 | static double convert64bitsToTs(uint64_t bits) 81 | { 82 | uint32_t usecs = (uint32_t) (bits & 0xffffffff); 83 | uint32_t secs = (uint32_t) ((bits >> 32) & 0xffffffff); 84 | double ts = (secs) + ((double) usecs) / 1000000.0; 85 | 86 | return ts; 87 | } 88 | 89 | p3EasyTransport::p3EasyTransport(RsPluginHandler *handler,EasyTransportNotify *notifier) 90 | : RsPQIService(RS_SERVICE_TYPE_EasyTransport_PLUGIN,0,handler), mEasyTransportMtx("p3EasyTransport"), mServiceControl(handler->getServiceControl()) , mNotify(notifier) 91 | { 92 | addSerialType(new RsEasyTransportSerialiser()); 93 | 94 | mSentPingTime = 0; 95 | mSentBandwidthInfoTime = 0; 96 | mCounter = 0; 97 | 98 | //plugin default configuration 99 | _atransmit = 0; 100 | _voice_hold = 75; 101 | _vadmin = 16018; 102 | _vadmax = 23661; 103 | _min_loudness = 4702; 104 | _noise_suppress = -45; 105 | _echo_cancel = true; 106 | 107 | } 108 | RsServiceInfo p3EasyTransport::getServiceInfo() 109 | { 110 | const std::string TURTLE_APP_NAME = "EasyTransport"; 111 | const uint16_t TURTLE_APP_MAJOR_VERSION = 1; 112 | const uint16_t TURTLE_APP_MINOR_VERSION = 0; 113 | const uint16_t TURTLE_MIN_MAJOR_VERSION = 1; 114 | const uint16_t TURTLE_MIN_MINOR_VERSION = 0; 115 | 116 | return RsServiceInfo(RS_SERVICE_TYPE_EasyTransport_PLUGIN, 117 | TURTLE_APP_NAME, 118 | TURTLE_APP_MAJOR_VERSION, 119 | TURTLE_APP_MINOR_VERSION, 120 | TURTLE_MIN_MAJOR_VERSION, 121 | TURTLE_MIN_MINOR_VERSION); 122 | } 123 | 124 | int p3EasyTransport::tick() 125 | { 126 | #ifdef DEBUG_EasyTransport 127 | std::cerr << "ticking p3EasyTransport" << std::endl; 128 | #endif 129 | 130 | //processIncoming(); 131 | //sendPackets(); 132 | 133 | return 0; 134 | } 135 | 136 | int p3EasyTransport::status() 137 | { 138 | return 1; 139 | } 140 | 141 | int p3EasyTransport::sendPackets() 142 | { 143 | time_t now = time(NULL); 144 | time_t pt; 145 | time_t pt2; 146 | { 147 | RsStackMutex stack(mEasyTransportMtx); /****** LOCKED MUTEX *******/ 148 | pt = mSentPingTime; 149 | pt2 = mSentBandwidthInfoTime; 150 | } 151 | 152 | if (now > pt + EasyTransport_PING_PERIOD) 153 | { 154 | sendPingMeasurements(); 155 | 156 | RsStackMutex stack(mEasyTransportMtx); /****** LOCKED MUTEX *******/ 157 | mSentPingTime = now; 158 | } 159 | if (now > pt2 + EasyTransport_BANDWIDTH_PERIOD) 160 | { 161 | sendBandwidthInfo(); 162 | 163 | RsStackMutex stack(mEasyTransportMtx); /****** LOCKED MUTEX *******/ 164 | mSentBandwidthInfoTime = now; 165 | } 166 | return true ; 167 | } 168 | void p3EasyTransport::sendBandwidthInfo() 169 | { 170 | std::set onlineIds; 171 | mServiceControl->getPeersConnected(getServiceInfo().mServiceType, onlineIds); 172 | 173 | RsStackMutex stack(mEasyTransportMtx); /****** LOCKED MUTEX *******/ 174 | 175 | for(std::map::iterator it(mPeerInfo.begin());it!=mPeerInfo.end();++it) 176 | { 177 | it->second.average_incoming_bandwidth = 0.75 * it->second.average_incoming_bandwidth + 0.25 * it->second.total_bytes_received / EasyTransport_BANDWIDTH_PERIOD ; 178 | it->second.total_bytes_received = 0 ; 179 | 180 | if(onlineIds.find(it->first) == onlineIds.end() || it->second.average_incoming_bandwidth == 0) 181 | continue ; 182 | 183 | std::cerr << "average bandwidth for peer " << it->first << ": " << it->second.average_incoming_bandwidth << " Bps" << std::endl; 184 | sendEasyTransportBandwidth(it->first,it->second.average_incoming_bandwidth) ; 185 | } 186 | } 187 | 188 | int p3EasyTransport::sendEasyTransportHangUpCall(const RsPeerId &peer_id) 189 | { 190 | RsEasyTransportProtocolItem *item = new RsEasyTransportProtocolItem ; 191 | 192 | item->protocol = RsEasyTransportProtocolItem::EasyTransportProtocol_Close; 193 | item->flags = 0 ; 194 | item->PeerId(peer_id) ; 195 | 196 | sendItem(item) ; 197 | 198 | return true ; 199 | } 200 | int p3EasyTransport::sendEasyTransportAcceptCall(const RsPeerId& peer_id) 201 | { 202 | RsEasyTransportProtocolItem *item = new RsEasyTransportProtocolItem ; 203 | 204 | item->protocol = RsEasyTransportProtocolItem::EasyTransportProtocol_Ackn ; 205 | item->flags = 0 ; 206 | item->PeerId(peer_id) ; 207 | 208 | sendItem(item) ; 209 | 210 | return true ; 211 | } 212 | void p3EasyTransport::msg_peer(std::string msg, RsPeerId peerId){ 213 | 214 | //std::set onlineIds; 215 | std::list< RsPeerId > onlineIds; 216 | // mServiceControl->getPeersConnected(getServiceInfo().mServiceType, onlineIds); 217 | rsPeers->getOnlineList(onlineIds); 218 | 219 | double ts = getCurrentTS(); 220 | 221 | #ifdef DEBUG_EasyTransport 222 | std::cerr << "p3EasyTransport::msg_peer() @ts: " << ts; 223 | std::cerr << std::endl; 224 | #endif 225 | 226 | /* prepare packets */ 227 | std::list::iterator it; 228 | //for(it = onlineIds.begin(); it != onlineIds.end(); it++) 229 | 230 | #ifdef DEBUG_EasyTransport 231 | std::cerr << "p3EasyTransport::msg_all() MSging: " << peerId; 232 | std::cerr << std::endl; 233 | #endif 234 | 235 | std::cout << "MSging: " << peerId.toStdString() << "\n"; 236 | /* create the packet */ 237 | RsEasyTransportDataItem *pingPkt = new RsEasyTransportDataItem(); 238 | pingPkt->PeerId(peerId); 239 | pingPkt->m_msg = msg; 240 | pingPkt->data_size = msg.size(); 241 | //pingPkt->mSeqNo = mCounter; 242 | //pingPkt->mPingTS = convertTsTo64bits(ts); 243 | 244 | //storePingAttempt(*it, ts, mCounter); 245 | 246 | #ifdef DEBUG_EasyTransport 247 | std::cerr << "p3EasyTransport::msg_all() With Packet:"; 248 | std::cerr << std::endl; 249 | pingPkt->print(std::cerr, 10); 250 | #endif 251 | 252 | sendItem(pingPkt); 253 | 254 | 255 | //RsStackMutex stack(mEasyTransportMtx); /****** LOCKED MUTEX *******/ 256 | //mCounter++; 257 | } 258 | void p3EasyTransport::msg_all(std::string msg){ 259 | 260 | //std::set onlineIds; 261 | std::list< RsPeerId > onlineIds; 262 | // mServiceControl->getPeersConnected(getServiceInfo().mServiceType, onlineIds); 263 | rsPeers->getOnlineList(onlineIds); 264 | 265 | double ts = getCurrentTS(); 266 | 267 | #ifdef DEBUG_EasyTransport 268 | std::cerr << "p3EasyTransport::msg_all() @ts: " << ts; 269 | std::cerr << std::endl; 270 | #endif 271 | 272 | std::cout << "READY TO BCast: " << onlineIds.size() << "\n"; 273 | /* prepare packets */ 274 | std::list::iterator it; 275 | for(it = onlineIds.begin(); it != onlineIds.end(); it++) 276 | { 277 | #ifdef DEBUG_EasyTransport 278 | std::cerr << "p3EasyTransport::msg_all() MSging: " << *it; 279 | std::cerr << std::endl; 280 | #endif 281 | 282 | std::cout << "MSging: " << (*it).toStdString() << "\n"; 283 | /* create the packet */ 284 | RsEasyTransportDataItem *pingPkt = new RsEasyTransportDataItem(); 285 | pingPkt->PeerId(*it); 286 | pingPkt->m_msg = msg; 287 | pingPkt->data_size = msg.size(); 288 | //pingPkt->mSeqNo = mCounter; 289 | //pingPkt->mPingTS = convertTsTo64bits(ts); 290 | 291 | //storePingAttempt(*it, ts, mCounter); 292 | 293 | #ifdef DEBUG_EasyTransport 294 | std::cerr << "p3EasyTransport::msg_all() With Packet:"; 295 | std::cerr << std::endl; 296 | pingPkt->print(std::cerr, 10); 297 | #endif 298 | 299 | sendItem(pingPkt); 300 | } 301 | 302 | //RsStackMutex stack(mEasyTransportMtx); /****** LOCKED MUTEX *******/ 303 | //mCounter++; 304 | } 305 | 306 | void p3EasyTransport::ping_all(){ 307 | this->sendPingMeasurements(); 308 | } 309 | 310 | void p3EasyTransport::broadcast_paint(int x, int y) 311 | { 312 | std::list< RsPeerId > onlineIds; 313 | // mServiceControl->getPeersConnected(getServiceInfo().mServiceType, onlineIds); 314 | rsPeers->getOnlineList(onlineIds); 315 | 316 | double ts = getCurrentTS(); 317 | 318 | 319 | std::cout << "READY TO PAINT: " << onlineIds.size() << "\n"; 320 | /* prepare packets */ 321 | std::list::iterator it; 322 | for(it = onlineIds.begin(); it != onlineIds.end(); it++) 323 | { 324 | 325 | std::cout << "painting to: " << (*it).toStdString() << "\n"; 326 | /* create the packet */ 327 | RsEasyTransportPaintItem *ppkt = new RsEasyTransportPaintItem(); 328 | ppkt->x = x; 329 | ppkt->y = y; 330 | 331 | ppkt->PeerId(*it); 332 | 333 | 334 | sendItem(ppkt); 335 | } 336 | } 337 | 338 | /*int p3EasyTransport::sendEasyTransportPing(const RsPeerId &peer_id) 339 | { 340 | RsEasyTransportPingItem *item = new RsEasyTransportPingItem ; 341 | 342 | item->protocol = RsEasyTransportProtocolItem::EasyTransportProtocol_Ring ; 343 | item->flags = 0 ; 344 | item->PeerId(peer_id) ; 345 | 346 | sendItem(item) ; 347 | 348 | return true ; 349 | }*/ 350 | int p3EasyTransport::sendEasyTransportRinging(const RsPeerId &peer_id) 351 | { 352 | RsEasyTransportProtocolItem *item = new RsEasyTransportProtocolItem ; 353 | 354 | item->protocol = RsEasyTransportProtocolItem::EasyTransportProtocol_Ring ; 355 | item->flags = 0 ; 356 | item->PeerId(peer_id) ; 357 | 358 | sendItem(item) ; 359 | 360 | return true ; 361 | } 362 | int p3EasyTransport::sendEasyTransportBandwidth(const RsPeerId &peer_id,uint32_t bytes_per_sec) 363 | { 364 | RsEasyTransportProtocolItem *item = new RsEasyTransportProtocolItem ; 365 | 366 | item->protocol = RsEasyTransportProtocolItem::EasyTransportProtocol_Bandwidth ; 367 | item->flags = bytes_per_sec ; 368 | item->PeerId(peer_id) ; 369 | 370 | sendItem(item) ; 371 | 372 | return true ; 373 | } 374 | int p3EasyTransport::sendEasyTransportData(const RsPeerId& peer_id,const RsEasyTransportDataChunk& chunk) 375 | { 376 | #ifdef DEBUG_EasyTransport 377 | std::cerr << "Sending " << chunk.size << " bytes of net_example data." << std::endl; 378 | #endif 379 | 380 | RsEasyTransportDataItem *item = new RsEasyTransportDataItem ; 381 | 382 | if(!item) 383 | { 384 | std::cerr << "Cannot allocate RsEasyTransportDataItem !" << std::endl; 385 | return false ; 386 | } 387 | std::string tChunk = "Hello Test!!"; 388 | /*item->net_example_data = malloc(chunk.size) ; 389 | 390 | if(item->net_example_data == NULL) 391 | { 392 | std::cerr << "Cannot allocate RsEasyTransportDataItem.net_example_data of size " << chunk.size << " !" << std::endl; 393 | delete item ; 394 | return false ; 395 | } 396 | memcpy(item->net_example_data,chunk.data,chunk.size) ;*/ 397 | item->PeerId(peer_id) ; 398 | item->data_size = tChunk.size(); 399 | 400 | if(chunk.type == RsEasyTransportDataChunk::RS_EasyTransport_DATA_TYPE_AUDIO) 401 | item->flags = RS_EasyTransport_FLAGS_AUDIO_DATA ; 402 | else if(chunk.type == RsEasyTransportDataChunk::RS_EasyTransport_DATA_TYPE_VIDEO) 403 | item->flags = RS_EasyTransport_FLAGS_VIDEO_DATA ; 404 | else 405 | { 406 | std::cerr << "(EE) p3EasyTransport: cannot send chunk data. Unknown data type = " << chunk.type << std::endl; 407 | delete item ; 408 | return false ; 409 | } 410 | 411 | sendItem(item) ; 412 | 413 | return true ; 414 | } 415 | 416 | void p3EasyTransport::sendPingMeasurements() 417 | { 418 | /* we ping our peers */ 419 | /* who is online? */ 420 | //if(!mServiceControl) 421 | // return ; 422 | 423 | //std::set onlineIds; 424 | std::list< RsPeerId > onlineIds; 425 | // mServiceControl->getPeersConnected(getServiceInfo().mServiceType, onlineIds); 426 | rsPeers->getOnlineList(onlineIds); 427 | 428 | double ts = getCurrentTS(); 429 | 430 | #ifdef DEBUG_EasyTransport 431 | std::cerr << "p3EasyTransport::sendPingMeasurements() @ts: " << ts; 432 | std::cerr << std::endl; 433 | #endif 434 | 435 | std::cout << "READY TO PING: " << onlineIds.size() << "\n"; 436 | /* prepare packets */ 437 | std::list::iterator it; 438 | for(it = onlineIds.begin(); it != onlineIds.end(); it++) 439 | { 440 | #ifdef DEBUG_EasyTransport 441 | std::cerr << "p3EasyTransport::sendPingMeasurements() Pinging: " << *it; 442 | std::cerr << std::endl; 443 | #endif 444 | 445 | std::cout << "pinging: " << (*it).toStdString() << "\n"; 446 | /* create the packet */ 447 | RsEasyTransportPingItem *pingPkt = new RsEasyTransportPingItem(); 448 | pingPkt->PeerId(*it); 449 | pingPkt->mSeqNo = mCounter; 450 | pingPkt->mPingTS = convertTsTo64bits(ts); 451 | 452 | storePingAttempt(*it, ts, mCounter); 453 | 454 | #ifdef DEBUG_EasyTransport 455 | std::cerr << "p3EasyTransport::sendPingMeasurements() With Packet:"; 456 | std::cerr << std::endl; 457 | pingPkt->print(std::cerr, 10); 458 | #endif 459 | 460 | sendItem(pingPkt); 461 | } 462 | 463 | RsStackMutex stack(mEasyTransportMtx); /****** LOCKED MUTEX *******/ 464 | mCounter++; 465 | } 466 | 467 | 468 | void p3EasyTransport::handlePaint(RsEasyTransportPaintItem *item) 469 | { 470 | 471 | RsStackMutex stack(mEasyTransportMtx); /****** LOCKED MUTEX *******/ //unneeded? 472 | 473 | // store the data in a queue. 474 | 475 | 476 | mNotify->notifyReceivedPaint(item->PeerId(), item->x,item->y); 477 | } 478 | 479 | void p3EasyTransport::handleProtocol(RsEasyTransportProtocolItem *item) 480 | { 481 | // should we keep a list of received requests? 482 | 483 | /*switch(item->protocol) 484 | { 485 | case RsEasyTransportProtocolItem::EasyTransportProtocol_Ring: mNotify->notifyReceivedEasyTransportInvite(item->PeerId()); 486 | #ifdef DEBUG_EasyTransport 487 | std::cerr << "p3EasyTransport::handleProtocol(): Received protocol ring item." << std::endl; 488 | #endif 489 | break ; 490 | 491 | case RsEasyTransportProtocolItem::EasyTransportProtocol_Ackn: mNotify->notifyReceivedEasyTransportAccept(item->PeerId()); 492 | #ifdef DEBUG_EasyTransport 493 | std::cerr << "p3EasyTransport::handleProtocol(): Received protocol accept call" << std::endl; 494 | #endif 495 | break ; 496 | 497 | case RsEasyTransportProtocolItem::EasyTransportProtocol_Close: mNotify->notifyReceivedEasyTransportHangUp(item->PeerId()); 498 | #ifdef DEBUG_EasyTransport 499 | std::cerr << "p3EasyTransport::handleProtocol(): Received protocol Close call." << std::endl; 500 | #endif 501 | break ; 502 | case RsEasyTransportProtocolItem::EasyTransportProtocol_Bandwidth: mNotify->notifyReceivedEasyTransportBandwidth(item->PeerId(),(uint32_t)item->flags); 503 | #ifdef DEBUG_EasyTransport 504 | std::cerr << "p3EasyTransport::handleProtocol(): Received protocol bandwidth. Value=" << item->flags << std::endl; 505 | #endif 506 | break ; 507 | default: 508 | #ifdef DEBUG_EasyTransport 509 | std::cerr << "p3EasyTransport::handleProtocol(): Received protocol item # " << item->protocol << ": not handled yet ! Sorry" << std::endl; 510 | #endif 511 | break ; 512 | }*/ 513 | 514 | } 515 | 516 | void p3EasyTransport::handleData(RsEasyTransportDataItem *item) 517 | { 518 | RsStackMutex stack(mEasyTransportMtx); /****** LOCKED MUTEX *******/ 519 | 520 | // store the data in a queue. 521 | 522 | 523 | mNotify->notifyReceivedMsg(item->PeerId(), QString::fromStdString(item->m_msg)); 524 | /* 525 | std::map::iterator it = mPeerInfo.find(item->PeerId()) ; 526 | 527 | if(it == mPeerInfo.end()) 528 | { 529 | std::cerr << "Peer unknown to EasyTransport process. Dropping data" << std::endl; 530 | delete item ; 531 | return ; 532 | } 533 | it->second.incoming_queue.push_back(item) ; // be careful with the delete action! 534 | 535 | // For Video data, measure the bandwidth 536 | 537 | if(item->flags & RS_EasyTransport_FLAGS_VIDEO_DATA) 538 | it->second.total_bytes_received += item->data_size ; 539 | 540 | //mNotify->notifyReceivedEasyTransportData(item->PeerId());*/ 541 | } 542 | 543 | bool p3EasyTransport::getIncomingData(const RsPeerId& peer_id,std::vector& incoming_data_chunks) 544 | { 545 | RsStackMutex stack(mEasyTransportMtx); /****** LOCKED MUTEX *******/ 546 | 547 | incoming_data_chunks.clear() ; 548 | 549 | std::map::iterator it = mPeerInfo.find(peer_id) ; 550 | 551 | if(it == mPeerInfo.end()) 552 | { 553 | std::cerr << "Peer unknown to EasyTransport process. No data returned. Probably a bug !" << std::endl; 554 | return false ; 555 | } 556 | for(std::list::const_iterator it2(it->second.incoming_queue.begin());it2!=it->second.incoming_queue.end();++it2) 557 | { 558 | /*RsEasyTransportDataChunk chunk ; 559 | chunk.size = (*it2)->data_size ; 560 | chunk.data = malloc((*it2)->data_size) ; 561 | 562 | uint32_t type_flags = (*it2)->flags & (RS_EasyTransport_FLAGS_AUDIO_DATA | RS_EasyTransport_FLAGS_VIDEO_DATA) ; 563 | if(type_flags == RS_EasyTransport_FLAGS_AUDIO_DATA) 564 | chunk.type = RsEasyTransportDataChunk::RS_EasyTransport_DATA_TYPE_AUDIO ; 565 | else if(type_flags == RS_EasyTransport_FLAGS_VIDEO_DATA) 566 | chunk.type = RsEasyTransportDataChunk::RS_EasyTransport_DATA_TYPE_VIDEO ; 567 | else 568 | { 569 | std::cerr << "(EE) p3EasyTransport::getIncomingData(): error. Cannot handle item with unknown type " << type_flags << std::endl; 570 | delete *it2 ; 571 | free(chunk.data) ; 572 | continue ; 573 | } 574 | 575 | memcpy(chunk.data,(*it2)->net_example_data,(*it2)->data_size) ; 576 | 577 | incoming_data_chunks.push_back(chunk) ;*/ 578 | 579 | delete *it2 ; 580 | } 581 | 582 | it->second.incoming_queue.clear() ; 583 | 584 | return true ; 585 | } 586 | 587 | bool p3EasyTransport::recvItem(RsItem *item) 588 | { 589 | /* pass to specific handler */ 590 | bool keep = false ; 591 | 592 | switch(item->PacketSubType()) 593 | { 594 | case RS_PKT_SUBTYPE_EasyTransport_PING: 595 | handlePing(dynamic_cast(item)); 596 | break; 597 | 598 | case RS_PKT_SUBTYPE_EasyTransport_PONG: 599 | handlePong(dynamic_cast(item)); 600 | break; 601 | 602 | case RS_PKT_SUBTYPE_EasyTransport_PROTOCOL: 603 | handleProtocol(dynamic_cast(item)) ; 604 | break ; 605 | case RS_PKT_SUBTYPE_EasyTransport_PAINT: 606 | handlePaint(dynamic_cast(item)) ; 607 | break ; 608 | 609 | case RS_PKT_SUBTYPE_EasyTransport_DATA: 610 | handleData(dynamic_cast(item)); 611 | keep = true ; 612 | break; 613 | #if 0 614 | /* THESE ARE ALL FUTURISTIC DATA TYPES */ 615 | case RS_BANDWIDTH_PING_ITEM: 616 | handleBandwidthPing(item); 617 | break; 618 | 619 | case RS_BANDWIDTH_PONG_ITEM: 620 | handleBandwidthPong(item); 621 | break; 622 | #endif 623 | default: 624 | break; 625 | } 626 | 627 | /* clean up */ 628 | if(!keep) 629 | delete item; 630 | return true ; 631 | } 632 | 633 | int p3EasyTransport::handlePing(RsEasyTransportPingItem *ping) 634 | { 635 | /* cast to right type */ 636 | 637 | //#ifdef DEBUG_EasyTransport 638 | std::cout << "p3EasyTransport::handlePing() Recvd Packet from: " << ping->PeerId(); 639 | std::cout << std::endl; 640 | //#endif 641 | mNotify->notifyReceivedMsg(ping->PeerId(), "ping"); 642 | 643 | /* with a ping, we just respond as quickly as possible - they do all the analysis */ 644 | RsEasyTransportPongItem *pong = new RsEasyTransportPongItem(); 645 | 646 | 647 | pong->PeerId(ping->PeerId()); 648 | pong->mPingTS = ping->mPingTS; 649 | pong->mSeqNo = ping->mSeqNo; 650 | 651 | // add our timestamp. 652 | double ts = getCurrentTS(); 653 | pong->mPongTS = convertTsTo64bits(ts); 654 | 655 | 656 | #ifdef DEBUG_EasyTransport 657 | std::cerr << "p3EasyTransport::handlePing() With Packet:"; 658 | std::cerr << std::endl; 659 | pong->print(std::cerr, 10); 660 | #endif 661 | 662 | sendItem(pong); 663 | return true ; 664 | } 665 | 666 | 667 | int p3EasyTransport::handlePong(RsEasyTransportPongItem *pong) 668 | { 669 | /* cast to right type */ 670 | 671 | //#ifdef DEBUG_EasyTransport 672 | std::cout << "p3EasyTransport::handlePong() Recvd Packet from: " << pong->PeerId(); 673 | std::cout << std::endl; 674 | pong->print(std::cout, 10); 675 | //#endif 676 | mNotify->notifyReceivedMsg(pong->PeerId(), "pong"); 677 | 678 | /* with a pong, we do the maths! */ 679 | double recvTS = getCurrentTS(); 680 | double pingTS = convert64bitsToTs(pong->mPingTS); 681 | double pongTS = convert64bitsToTs(pong->mPongTS); 682 | 683 | double rtt = recvTS - pingTS; 684 | double offset = pongTS - (recvTS - rtt / 2.0); // so to get to their time, we go ourTS + offset. 685 | 686 | #ifdef DEBUG_EasyTransport 687 | std::cerr << "p3EasyTransport::handlePong() Timing:"; 688 | std::cerr << std::endl; 689 | std::cerr << "\tpingTS: " << pingTS; 690 | std::cerr << std::endl; 691 | std::cerr << "\tpongTS: " << pongTS; 692 | std::cerr << std::endl; 693 | std::cerr << "\trecvTS: " << recvTS; 694 | std::cerr << std::endl; 695 | std::cerr << "\t ==> rtt: " << rtt; 696 | std::cerr << std::endl; 697 | std::cerr << "\t ==> offset: " << offset; 698 | std::cerr << std::endl; 699 | #endif 700 | 701 | storePongResult(pong->PeerId(), pong->mSeqNo, pingTS, rtt, offset); 702 | return true ; 703 | } 704 | 705 | int p3EasyTransport::storePingAttempt(const RsPeerId& id, double ts, uint32_t seqno) 706 | { 707 | RsStackMutex stack(mEasyTransportMtx); /****** LOCKED MUTEX *******/ 708 | 709 | /* find corresponding local data */ 710 | EasyTransportPeerInfo *peerInfo = locked_GetPeerInfo(id); 711 | 712 | peerInfo->mCurrentPingTS = ts; 713 | peerInfo->mCurrentPingCounter = seqno; 714 | 715 | peerInfo->mSentPings++; 716 | if (!peerInfo->mCurrentPongRecvd) 717 | { 718 | peerInfo->mLostPongs++; 719 | } 720 | 721 | peerInfo->mCurrentPongRecvd = true; 722 | 723 | return 1; 724 | } 725 | 726 | 727 | 728 | int p3EasyTransport::storePongResult(const RsPeerId &id, uint32_t counter, double ts, double rtt, double offset) 729 | { 730 | RsStackMutex stack(mEasyTransportMtx); /****** LOCKED MUTEX *******/ 731 | 732 | /* find corresponding local data */ 733 | EasyTransportPeerInfo *peerInfo = locked_GetPeerInfo(id); 734 | 735 | if (peerInfo->mCurrentPingCounter != counter) 736 | { 737 | #ifdef DEBUG_EasyTransport 738 | std::cerr << "p3EasyTransport::storePongResult() ERROR Severly Delayed Measurements!" << std::endl; 739 | #endif 740 | } 741 | else 742 | { 743 | peerInfo->mCurrentPongRecvd = true; 744 | } 745 | 746 | peerInfo->mPongResults.push_back(RsEasyTransportPongResult(ts, rtt, offset)); 747 | 748 | 749 | while(peerInfo->mPongResults.size() > MAX_PONG_RESULTS) 750 | { 751 | peerInfo->mPongResults.pop_front(); 752 | } 753 | 754 | /* should do calculations */ 755 | return 1; 756 | } 757 | 758 | 759 | uint32_t p3EasyTransport::getPongResults(const RsPeerId& id, int n, std::list &results) 760 | { 761 | RsStackMutex stack(mEasyTransportMtx); /****** LOCKED MUTEX *******/ 762 | 763 | EasyTransportPeerInfo *peer = locked_GetPeerInfo(id); 764 | 765 | std::list::reverse_iterator it; 766 | int i = 0; 767 | for(it = peer->mPongResults.rbegin(); (it != peer->mPongResults.rend()) && (i < n); it++, i++) 768 | { 769 | /* reversing order - so its easy to trim later */ 770 | results.push_back(*it); 771 | } 772 | return i ; 773 | } 774 | 775 | 776 | 777 | EasyTransportPeerInfo *p3EasyTransport::locked_GetPeerInfo(const RsPeerId &id) 778 | { 779 | std::map::iterator it; 780 | it = mPeerInfo.find(id); 781 | if (it == mPeerInfo.end()) 782 | { 783 | /* add it in */ 784 | EasyTransportPeerInfo pinfo; 785 | 786 | /* initialise entry */ 787 | pinfo.initialisePeerInfo(id); 788 | 789 | mPeerInfo[id] = pinfo; 790 | 791 | it = mPeerInfo.find(id); 792 | } 793 | 794 | return &(it->second); 795 | } 796 | 797 | bool EasyTransportPeerInfo::initialisePeerInfo(const RsPeerId& id) 798 | { 799 | mId = id; 800 | 801 | /* reset variables */ 802 | mCurrentPingTS = 0; 803 | mCurrentPingCounter = 0; 804 | mCurrentPongRecvd = true; 805 | 806 | mSentPings = 0; 807 | mLostPongs = 0; 808 | average_incoming_bandwidth = 0 ; 809 | total_bytes_received = 0 ; 810 | 811 | mPongResults.clear(); 812 | 813 | return true; 814 | } 815 | 816 | 817 | RsTlvKeyValue p3EasyTransport::push_int_value(const std::string& key,int value) 818 | { 819 | RsTlvKeyValue kv ; 820 | kv.key = key ; 821 | rs_sprintf(kv.value, "%d", value); 822 | 823 | return kv ; 824 | } 825 | int p3EasyTransport::pop_int_value(const std::string& s) 826 | { 827 | std::istringstream is(s) ; 828 | 829 | int val ; 830 | is >> val ; 831 | 832 | return val ; 833 | } 834 | 835 | bool p3EasyTransport::saveList(bool& cleanup, std::list& lst) 836 | { 837 | cleanup = true ; 838 | 839 | RsConfigKeyValueSet *vitem = new RsConfigKeyValueSet ; 840 | 841 | vitem->tlvkvs.pairs.push_back(push_int_value("P3EasyTransport_CONFIG_ATRANSMIT",_atransmit)) ; 842 | vitem->tlvkvs.pairs.push_back(push_int_value("P3EasyTransport_CONFIG_VOICEHOLD",_voice_hold)) ; 843 | vitem->tlvkvs.pairs.push_back(push_int_value("P3EasyTransport_CONFIG_VADMIN" ,_vadmin)) ; 844 | vitem->tlvkvs.pairs.push_back(push_int_value("P3EasyTransport_CONFIG_VADMAX" ,_vadmax)) ; 845 | vitem->tlvkvs.pairs.push_back(push_int_value("P3EasyTransport_CONFIG_NOISE_SUP",_noise_suppress)) ; 846 | vitem->tlvkvs.pairs.push_back(push_int_value("P3EasyTransport_CONFIG_MIN_LOUDN",_min_loudness)) ; 847 | vitem->tlvkvs.pairs.push_back(push_int_value("P3EasyTransport_CONFIG_ECHO_CNCL",_echo_cancel)) ; 848 | 849 | lst.push_back(vitem) ; 850 | 851 | return true ; 852 | } 853 | bool p3EasyTransport::loadList(std::list& load) 854 | { 855 | for(std::list::const_iterator it(load.begin());it!=load.end();++it) 856 | { 857 | #ifdef P3TURTLE_DEBUG 858 | assert(item!=NULL) ; 859 | #endif 860 | RsConfigKeyValueSet *vitem = dynamic_cast(*it) ; 861 | 862 | if(vitem != NULL) 863 | for(std::list::const_iterator kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); ++kit) 864 | if(kit->key == "P3EasyTransport_CONFIG_ATRANSMIT") 865 | _atransmit = pop_int_value(kit->value) ; 866 | else if(kit->key == "P3EasyTransport_CONFIG_VOICEHOLD") 867 | _voice_hold = pop_int_value(kit->value) ; 868 | else if(kit->key == "P3EasyTransport_CONFIG_VADMIN") 869 | _vadmin = pop_int_value(kit->value) ; 870 | else if(kit->key == "P3EasyTransport_CONFIG_VADMAX") 871 | _vadmax = pop_int_value(kit->value) ; 872 | else if(kit->key == "P3EasyTransport_CONFIG_NOISE_SUP") 873 | _noise_suppress = pop_int_value(kit->value) ; 874 | else if(kit->key == "P3EasyTransport_CONFIG_MIN_LOUDN") 875 | _min_loudness = pop_int_value(kit->value) ; 876 | else if(kit->key == "P3EasyTransport_CONFIG_ECHO_CNCL") 877 | _echo_cancel = pop_int_value(kit->value) ; 878 | 879 | delete vitem ; 880 | } 881 | 882 | return true ; 883 | } 884 | 885 | RsSerialiser *p3EasyTransport::setupSerialiser() 886 | { 887 | RsSerialiser *rsSerialiser = new RsSerialiser(); 888 | rsSerialiser->addSerialType(new RsEasyTransportSerialiser()); 889 | rsSerialiser->addSerialType(new RsGeneralConfigSerialiser()); 890 | 891 | return rsSerialiser ; 892 | } 893 | 894 | 895 | 896 | 897 | 898 | 899 | 900 | 901 | 902 | 903 | -------------------------------------------------------------------------------- /gui/images/talking_off.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 21 | talking_off 23 | 46 | 49 | 50 | 52 | 55 | 59 | 63 | 64 | 67 | 71 | 75 | 76 | 78 | 82 | 86 | 87 | 90 | 94 | 98 | 99 | 102 | 106 | 110 | 111 | 114 | 118 | 122 | 123 | 126 | 130 | 134 | 135 | 138 | 142 | 146 | 147 | 150 | 154 | 158 | 159 | 161 | 165 | 169 | 173 | 174 | 181 | 188 | 195 | 202 | 209 | 216 | 223 | 230 | 237 | 244 | 255 | 257 | 261 | 265 | 269 | 270 | 277 | 284 | 291 | 298 | 305 | 310 | 314 | 323 | 324 | 331 | 342 | 345 | 349 | 353 | 354 | 360 | 364 | 373 | 378 | 383 | 392 | 393 | 400 | 407 | 414 | 421 | 432 | 435 | 439 | 443 | 444 | 450 | 454 | 463 | 468 | 473 | 482 | 483 | 490 | 501 | 504 | 508 | 512 | 513 | 519 | 523 | 532 | 533 | 540 | 547 | 554 | 561 | 568 | 575 | 582 | 589 | 596 | 603 | 610 | 617 | 624 | 631 | 638 | 645 | 652 | 659 | 664 | 669 | 678 | 684 | 689 | 697 | 701 | 702 | 709 | 717 | 718 | 725 | 732 | 743 | 750 | 761 | 764 | 768 | 772 | 773 | 784 | 787 | 791 | 795 | 796 | 807 | 814 | 825 | 828 | 832 | 836 | 837 | 848 | 851 | 855 | 859 | 860 | 871 | 878 | 889 | 891 | 895 | 899 | 900 | 911 | 914 | 918 | 922 | 923 | 934 | 945 | 952 | 963 | 966 | 970 | 974 | 975 | 986 | 989 | 993 | 997 | 998 | 1009 | 1016 | 1027 | 1030 | 1034 | 1038 | 1039 | 1050 | 1053 | 1057 | 1061 | 1062 | 1073 | 1082 | 1087 | 1096 | 1100 | 1106 | 1111 | 1117 | 1124 | 1130 | 1131 | 1138 | 1145 | 1152 | 1159 | 1166 | 1173 | 1180 | 1191 | 1193 | 1197 | 1201 | 1202 | 1213 | 1216 | 1220 | 1224 | 1225 | 1236 | 1247 | 1258 | 1265 | 1276 | 1279 | 1283 | 1287 | 1288 | 1299 | 1302 | 1306 | 1310 | 1311 | 1322 | 1333 | 1344 | 1355 | 1366 | 1377 | 1384 | 1386 | 1390 | 1394 | 1395 | 1406 | 1408 | 1412 | 1416 | 1417 | 1428 | 1431 | 1435 | 1439 | 1440 | 1447 | 1454 | 1463 | 1465 | 1469 | 1473 | 1474 | 1481 | 1492 | 1494 | 1498 | 1502 | 1503 | 1510 | 1520 | 1531 | 1542 | 1553 | 1564 | 1575 | 1586 | 1593 | 1604 | 1607 | 1611 | 1615 | 1616 | 1627 | 1630 | 1634 | 1638 | 1639 | 1650 | 1661 | 1668 | 1679 | 1682 | 1686 | 1690 | 1691 | 1702 | 1705 | 1709 | 1713 | 1714 | 1725 | 1736 | 1747 | 1758 | 1759 | 1761 | 1762 | 1764 | image/svg+xml 1765 | 1767 | talking_off 1768 | 1770 | 1771 | 1772 | Martin Skilnand 1773 | 1774 | 1775 | 1776 | 1777 | Martin Skilnand 1778 | 1779 | 1780 | 2009.08.17 1781 | 1782 | 1783 | Mumble team 1784 | 1785 | 1786 | Icon for voice chat program mumble 1787 | 1788 | 1789 | mumble talking off 1790 | 1791 | 1792 | talking_off.svg 1793 | git://mumble.git.sourceforge.net/gitroot/mumble 1794 | 1795 | 1796 | 1797 | 1804 | 1814 | 1824 | 1833 | 1838 | 1847 | 1856 | 1865 | 1874 | 1883 | 1893 | 1898 | 1902 | 1903 | 1909 | 1914 | 1915 | 1921 | 1931 | 1941 | 1951 | 1961 | 1971 | 1981 | 1982 | 1983 | --------------------------------------------------------------------------------