Skip to content

Commit

Permalink
Merge with cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jcague committed Sep 11, 2013
2 parents 83de2de + c63db82 commit 4004537
Show file tree
Hide file tree
Showing 83 changed files with 4,760 additions and 883 deletions.
22 changes: 22 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Auto detect text files and perform LF normalization
* text=auto

# Custom for Visual Studio
*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union

# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
build/
lynckia_config.js
licode_config.js
extras/basic_example/node_modules
extras/basic_example/public/erizo.js
extras/basic_example/nuve.js
node_modules/
site
.DS_Store
libdeps/
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ before_install:
- ./scripts/installErizo.sh
- ./scripts/installNuve.sh
- ./scripts/installBasicExample.sh
- ./scripts/initLynckia.sh
- ./scripts/initLicode.sh
- sleep 10
- ./scripts/initBasicExample.sh
- ./.travis/scripts/install_chrome.sh
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
branches:
only: travis-test
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Licode

[![Build Status](https://travis-ci.org/ging/lynckia.png)](https://travis-ci.org/ging/lynckia)

More info at:
http://www.lynckia.com/licode
56 changes: 38 additions & 18 deletions erizo/src/erizo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,28 @@ cmake_minimum_required(VERSION 2.8)
find_package(PkgConfig)
#functions
function(test_lib LIB_NAME)
if (${LIB_NAME} MATCHES "^.*-NOTFOUND")
message(FATAL_ERROR "lib not found: " ${LIB_NAME} " check README")
return()
endif(${LIB_NAME} MATCHES "^.*-NOTFOUND")
if (${LIB_NAME} MATCHES "^.*-NOTFOUND")
message(FATAL_ERROR "lib not found: " ${LIB_NAME} " check README")
return()
endif(${LIB_NAME} MATCHES "^.*-NOTFOUND")
endfunction(test_lib)
project (ERIZO)

set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/")
set(ERIZO_VERSION_MAJOR 0)
set(ERIZO_VERSION_MINOR 1)
set(CMAKE_CXX_FLAGS "-g -Wall")

set(SSL_DIR /usr/local/ssl)
set(SSL_INCLUDE_DIR ${SSL_DIR}/include/openssl)

include_directories(${ERIZO_SOURCE_DIR} ${SSL_INCLUDE_DIR})

file(GLOB_RECURSE ERIZO_SOURCES ${ERIZO_SOURCE_DIR}/*.h ${ERIZO_SOURCE_DIR}/*.c ${ERIZO_SOURCE_DIR}/*.cpp)

file(GLOB_RECURSE ERIZO_SOURCES ${ERIZO_SOURCE_DIR}/*.cpp ${ERIZO_SOURCE_DIR}/*.h)
add_library(erizo SHARED ${ERIZO_SOURCES})

#GLIB
# GLIB
find_package(Glib REQUIRED)
include_directories(${GLIB_INCLUDE_DIRS})
target_link_libraries(erizo ${GLIB_LIBRARIES})
Expand All @@ -26,24 +33,37 @@ set (BOOST_LIBS thread regex system)
find_package(Boost COMPONENTS ${BOOST_LIBS} REQUIRED)
target_link_libraries(erizo ${Boost_LIBRARIES})

#THE REST
# SRTP
find_library(SRTP srtp)
test_lib(${SRTP})
set (LIBS ${LIBS} ${SRTP})
find_library(NICE nice)
test_lib(${NICE})
set (LIBS ${LIBS} ${NICE})

# NICE
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
find_library(NICE nice)
test_lib(${NICE})
set (OperatingSystem "Mac OS X")
else(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set (NICE /usr/local/lib/libnice.so)
endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")

# GTHREAD
find_library(GTHREAD gthread-2.0)
test_lib(${GTHREAD})
set (LIBS ${LIBS} ${GTHREAD})
find_library(AVUTIL libavutil.dylib avutil)

# OPENSSL
set(SSL_LIB ${SSL_DIR}/lib/libssl.a ${SSL_DIR}/lib/libcrypto.a)
target_link_libraries(erizo ${SRTP} ${NICE} ${GTHREAD} ${SSL_LIB})

# LIBAV
find_library(AVUTIL libavutil.dylib avutil PATHS /usr/local/lib)
test_lib(${AVUTIL})
set (LIBS ${LIBS} ${AVUTIL})
find_library(AVCODEC libavcodec.dylib avcodec)
set (LIBS ${AVUTIL})
find_library(AVCODEC libavcodec.dylib avcodec PATHS /usr/local/lib)
test_lib(${AVCODEC})
set (LIBS ${LIBS} ${AVCODEC})
find_library(AVFORMAT libavformat.dylib avformat)
find_library(AVFORMAT libavformat.dylib avformat PATHS /usr/local/lib)
test_lib(${AVFORMAT})
set (LIBS ${LIBS} ${AVFORMAT})
target_link_libraries(erizo ${LIBS})
message("Libs " ${LIBS})
message("AVLibs " ${LIBS})

target_link_libraries(erizo ${SRTP} ${NICE} ${GTHREAD} ${SSL_LIB} ${LIBS})
252 changes: 252 additions & 0 deletions erizo/src/erizo/DtlsTransport.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
/*
* DtlsConnection.cpp
*/
#include <iostream>
#include <cassert>

#include "DtlsTransport.h"
#include "NiceConnection.h"
#include "SrtpChannel.h"

#include "dtls/DtlsFactory.h"

#include "rtputils.h"

using namespace erizo;
using namespace std;
using namespace dtls;

DtlsTransport::DtlsTransport(MediaType med, const std::string &transport_name, bool bundle, bool rtcp_mux, TransportListener *transportListener):Transport(med, transport_name, bundle, rtcp_mux, transportListener) {
cout << "Initializing DtlsTransport" << endl;
updateTransportState(TRANSPORT_INITIAL);

readyRtp = false;
readyRtcp = false;

dtlsRtp = new DtlsSocketContext();
dtlsRtcp = NULL;

DtlsSocket *mSocket=(new DtlsFactory())->createClient(std::auto_ptr<DtlsSocketContext>(dtlsRtp));
dtlsRtp->setSocket(mSocket);
dtlsRtp->setDtlsReceiver(this);

srtp_ = NULL;
srtcp_ = NULL;
protectBuf_ =reinterpret_cast<char*>(malloc(10000));
unprotectBuf_ =reinterpret_cast<char*>(malloc(10000));
int comps = 1;
if (!rtcp_mux) {
comps = 2;
dtlsRtcp = new DtlsSocketContext();
mSocket=(new DtlsFactory())->createClient(std::auto_ptr<DtlsSocketContext>(dtlsRtcp));
dtlsRtcp->setSocket(mSocket);
dtlsRtcp->setDtlsReceiver(this);
}
bundle_ = bundle;
nice_ = new NiceConnection(med, transport_name, comps);
nice_->setNiceListener(this);
nice_->start();
}

DtlsTransport::~DtlsTransport() {

this->close();

free(protectBuf_);
free(unprotectBuf_);

}

void DtlsTransport::close() {
if (dtlsRtp != NULL) {
dtlsRtp->stop();
}
if (dtlsRtcp != NULL) {
dtlsRtcp->stop();
}
if (srtp_ != NULL) {
free(srtp_);
}
if (srtcp_ != NULL) {
free(srtcp_);
}
if (nice_ != NULL) {
nice_->close();
nice_->join();
delete nice_;
}
}

void DtlsTransport::onNiceData(unsigned int component_id, char* data, int len, NiceConnection* nice) {
boost::mutex::scoped_lock lock(readMutex_);
int length = len;
SrtpChannel *srtp = srtp_;

if (DtlsTransport::isDtlsPacket(data, len)) {
printf("Received DTLS message from %u\n", component_id);
if (component_id == 1) {
dtlsRtp->read(reinterpret_cast<unsigned char*>(data), len);
} else {
dtlsRtcp->read(reinterpret_cast<unsigned char*>(data), len);
}

return;
} else if (this->getTransportState() == TRANSPORT_READY) {
memset(unprotectBuf_, 0, len);
memcpy(unprotectBuf_, data, len);

if (dtlsRtcp != NULL && component_id == 2) {
srtp = srtcp_;
}

if (srtp != NULL){
rtcpheader *chead = reinterpret_cast<rtcpheader*> (unprotectBuf_);
if (chead->packettype == RTCP_Sender_PT ||
chead->packettype == RTCP_Receiver_PT ||
chead->packettype == RTCP_Feedback_PT){
if (chead->packettype == RTCP_Feedback_PT) {
printf("NACK received\n");
}

if(srtp->unprotectRtcp(unprotectBuf_, &length)<0)
return;
} else {
if(srtp->unprotectRtp(unprotectBuf_, &length)<0)
return;
}
} else {
return;
}

if (length <= 0)
return;

getTransportListener()->onTransportData(unprotectBuf_, length, this);
}
}

void DtlsTransport::write(char* data, int len) {
boost::mutex::scoped_lock lock(writeMutex_);
int length = len;
SrtpChannel *srtp = srtp_;

int comp = 1;
if (this->getTransportState() == TRANSPORT_READY) {
memset(protectBuf_, 0, len);
memcpy(protectBuf_, data, len);

rtcpheader *chead = reinterpret_cast<rtcpheader*> (protectBuf_);
if (chead->packettype == RTCP_Sender_PT || chead->packettype == RTCP_Receiver_PT || chead->packettype == RTCP_Feedback_PT) {
if (!rtcp_mux_) {
comp = 2;
}
if (dtlsRtcp != NULL) {
srtp = srtcp_;
}
if (srtp && nice_->iceState == NICE_READY) {
if(srtp->protectRtcp(protectBuf_, &length)<0) {
return;
}
}
}
else{
comp = 1;

if (srtp && nice_->iceState == NICE_READY) {
if(srtp->protectRtp(protectBuf_, &length)<0) {
return;
}
}
}
if (length <= 10) {
return;
}
if (nice_->iceState == NICE_READY) {
getTransportListener()->queueData(comp, protectBuf_, length, this);
}
}
}

void DtlsTransport::writeDtls(DtlsSocketContext *ctx, const unsigned char* data, unsigned int len) {
int comp = 1;
if (ctx == dtlsRtcp) {
comp = 2;
}
printf("Sending DTLS message to %d\n", comp);
nice_->sendData(comp, data, len);
}

void DtlsTransport::onHandshakeCompleted(DtlsSocketContext *ctx, std::string clientKey,std::string serverKey, std::string srtp_profile) {
if (ctx == dtlsRtp) {
printf("Setting RTP srtp params\n");
srtp_ = new SrtpChannel();
srtp_->setRtpParams((char*) clientKey.c_str(), (char*) serverKey.c_str());
readyRtp = true;
if (dtlsRtcp == NULL) {
readyRtcp = true;
}
}
if (ctx == dtlsRtcp) {
printf("Setting RTCP srtp params\n");
srtcp_ = new SrtpChannel();
srtcp_->setRtpParams((char*) clientKey.c_str(), (char*) serverKey.c_str());
readyRtcp = true;
}
if (readyRtp && readyRtcp) {
updateTransportState(TRANSPORT_READY);
}

}

std::string DtlsTransport::getMyFingerprint() {
return dtlsRtp->getFingerprint();
}

void DtlsTransport::updateIceState(IceState state, NiceConnection *conn) {
cout << "New NICE state " << state << " " << mediaType << " " << bundle_ << endl;
if (state == NICE_CANDIDATES_GATHERED) {
updateTransportState(TRANSPORT_STARTED);
}
if (state == NICE_READY) {
dtlsRtp->start();
if (dtlsRtcp != NULL) {
dtlsRtcp->start();
}
}
}

void DtlsTransport::processLocalSdp(SdpInfo *localSdp_) {
cout << "Processing Local SDP in DTLS Transport" << endl;
std::vector<CandidateInfo> *cands;
localSdp_->isFingerprint = true;
localSdp_->fingerprint = getMyFingerprint();
if (nice_->iceState >= NICE_CANDIDATES_GATHERED) {
cands = nice_->localCandidates;
cout << " Candidates: " << cands->size() << endl;
for (unsigned int it = 0; it < cands->size(); it++) {
CandidateInfo cand = cands->at(it);
cand.isBundle = bundle_;
// TODO Check if bundle
localSdp_->addCandidate(cand);
if (cand.isBundle) {
printf("Adding bundle candidate! %d\n", cand.mediaType);
cand.mediaType = AUDIO_TYPE;
localSdp_->addCandidate(cand);
}
}
}
cout << "Processed Local SDP in DTLS Transport" << endl;
}

bool DtlsTransport::isDtlsPacket(const char* buf, int len) {
int data = DtlsFactory::demuxPacket(reinterpret_cast<const unsigned char*>(buf),len);
switch(data)
{
case DtlsFactory::dtls:
return true;
break;
default:
return false;
break;
}
}
Loading

0 comments on commit 4004537

Please sign in to comment.