Skip to content

Commit

Permalink
datachannel, refactor: add support for webrtc direct.
Browse files Browse the repository at this point in the history
  • Loading branch information
xicilion committed May 16, 2024
1 parent 8b6016c commit 588537c
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 6 deletions.
7 changes: 7 additions & 0 deletions datachannel/include/rtc/configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ struct RTC_CPP_EXPORT Configuration {
bool enableIceUdpMux = false; // libjuice only
bool disableAutoNegotiation = false;
bool forceMediaTransport = false;
bool disableFingerprintVerification = false;

// Port range
uint16_t portRangeBegin = 1024;
Expand All @@ -86,6 +87,12 @@ struct RTC_CPP_EXPORT Configuration {

// Local maximum message size for Data Channels
optional<size_t> maxMessageSize;

optional<string> iceUfrag;
optional<string> icePwd;

optional<string> certPem;
optional<string> keyPem;
};

#ifdef RTC_ENABLE_WEBSOCKET
Expand Down
1 change: 1 addition & 0 deletions datachannel/include/rtc/description.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class RTC_CPP_EXPORT Description {
string typeString() const;
Role role() const;
string bundleMid() const;
string sessionId() const;
std::vector<string> iceOptions() const;
optional<string> iceUfrag() const;
optional<string> icePwd() const;
Expand Down
2 changes: 2 additions & 0 deletions datachannel/src/description.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ string Description::bundleMid() const {
return "0";
}

string Description::sessionId() const { return mSessionId; }

optional<string> Description::iceUfrag() const { return mIceUfrag; }

std::vector<string> Description::iceOptions() const { return mIceOptions; }
Expand Down
5 changes: 5 additions & 0 deletions datachannel/src/impl/icetransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ IceTransport::IceTransport(const Configuration &config, candidate_callback candi
mAgent = decltype(mAgent)(juice_create(&jconfig), juice_destroy);
if (!mAgent)
throw std::runtime_error("Failed to create the ICE agent");

if (config.iceUfrag.has_value() && config.icePwd.has_value()) {
juice_set_local_ice_attributes(mAgent.get(), config.iceUfrag.value().c_str(),
config.icePwd.value().c_str());
}
}

IceTransport::~IceTransport() {
Expand Down
19 changes: 14 additions & 5 deletions datachannel/src/impl/peerconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,17 @@ static LogCounter
"Number of unknown RTCP packet types over past second");

PeerConnection::PeerConnection(Configuration config_)
: config(std::move(config_)), mCertificate(make_certificate(config.certificateType)) {
: config(std::move(config_)) {
PLOG_VERBOSE << "Creating PeerConnection";

if( config.certPem.has_value() && config.keyPem.has_value() ) {
std::promise<certificate_ptr> cert;
cert.set_value(std::make_shared<Certificate>(Certificate::FromString(config.certPem.value(), config.keyPem.value())));
mCertificate = cert.get_future();
} else {
mCertificate = make_certificate(config.certificateType);
}

if (config.portRangeEnd && config.portRangeBegin > config.portRangeEnd)
throw std::invalid_argument("Invalid port range");

Expand Down Expand Up @@ -426,6 +434,9 @@ bool PeerConnection::checkFingerprint(const std::string &fingerprint) const {
if (!mRemoteDescription || !mRemoteDescription->fingerprint())
return false;

if (config.disableFingerprintVerification)
return true;

auto expectedFingerprint = mRemoteDescription->fingerprint()->value;
if (expectedFingerprint == fingerprint) {
PLOG_VERBOSE << "Valid fingerprint \"" << fingerprint << "\"";
Expand Down Expand Up @@ -858,10 +869,8 @@ void PeerConnection::validateRemoteDescription(const Description &description) {
if (activeMediaCount == 0)
throw std::invalid_argument("Remote description has no active media");

if (auto local = localDescription(); local && local->iceUfrag() && local->icePwd())
if (*description.iceUfrag() == *local->iceUfrag() &&
*description.icePwd() == *local->icePwd())
throw std::logic_error("Got the local description as remote description");
if (auto local = localDescription(); local && local->sessionId() == description.sessionId())
throw std::logic_error("Got the local description as remote description");

PLOG_VERBOSE << "Remote description looks valid";
}
Expand Down
2 changes: 1 addition & 1 deletion datachannel/src/impl/peerconnection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ struct PeerConnection : std::enable_shared_from_this<PeerConnection> {
void updateTrackSsrcCache(const Description &description);

const init_token mInitToken = Init::Instance().token();
const future_certificate_ptr mCertificate;
future_certificate_ptr mCertificate;

Processor mProcessor;
optional<Description> mLocalDescription, mRemoteDescription;
Expand Down

0 comments on commit 588537c

Please sign in to comment.