Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

accessing private member of mbedtls with a portable macro #1039

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ compile_commands.json
/tests
.DS_Store
.idea

build-host/
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ if(NOT NO_EXAMPLES)
endif()
if(NOT NO_MEDIA AND NOT NO_WEBSOCKET)
add_subdirectory(examples/streamer)
add_subdirectory(examples/videocall)
endif()
add_subdirectory(examples/copy-paste)
add_subdirectory(examples/copy-paste-capi)
Expand Down
2 changes: 1 addition & 1 deletion deps/libjuice
Submodule libjuice updated 3 files
+9 −11 CMakeLists.txt
+2 −7 src/agent.c
+0 −2 src/socket.h
156 changes: 156 additions & 0 deletions examples/signaling-server-python-gjw/signaling-server-gjw.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
#!/usr/bin/env python3
#
# Python signaling server example for libdatachannel
# Copyright (c) 2020 Paul-Louis Ageneau
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.

import sys
import ssl
import json
import asyncio
import logging
import websockets


logger = logging.getLogger('websockets')
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler(sys.stdout))

# bookkeeping the clients' ids and the websocket instance
clients = {}

# bookkeeping the clients' ids and it's peer's id
peermap = {}

# basic APIs:
# join/{clientid}
# indicates a client has login to the server and may want to
# connect to a peer later on, we don't handle Dos attach for now!
#
# offer/{peerid}
# indicates a client attempts to negotiate a connection to a peer
# reject if the peer is alread in connection or the peer hasn't joined
#

async def sendResponse(websocket, id, type):
message = {}
message["id"] = id
message["type"] = type

print(f"Client id: {id}, type: {type}")

data = json.dumps(message)

await websocket.send(data)

async def handle_websocket(websocket, path):
client_id = None
destination_id = None
try:
splitted = path.split('/')
splitted.pop(0)

request = splitted.pop(0)

client_id = None

if request == "join":
client_id = splitted.pop(0)
else:
raise RuntimeError("Not implemented yet")

if not client_id:
raise RuntimeError("Missing client ID")

if client_id in clients:
raise RuntimeError("Duplicated request for join")

clients[client_id] = websocket

while True:
data = await websocket.recv()
print('From Client {} >> {}'.format(client_id, data))

message = json.loads(data)

destination_id = message['id']
destination_websocket = clients.get(destination_id)

request = message['type']

if not destination_websocket:
print('Peer {} not found'.format(destination_id))
await sendResponse(websocket, client_id, "useroffline")
continue

# reject multiple request for peerconnection
if request == "offer" and (client_id in peermap or destination_id in peermap):
print('Client {} already in peerconnection'.format(client_id))
await sendResponse(websocket, client_id, "userbusy")
continue

if request == "bye":
print('Client {} requests to leave'.format(client_id))
await sendResponse(destination_websocket, client_id, "bye")
break

# map the peer id to this client if necessary
# offer/answer
peermap[client_id] = destination_id

print("Sending message to {}".format(destination_id))

message['id'] = client_id
data = json.dumps(message)

print('To Client {} << {}'.format(destination_id, data))

await destination_websocket.send(data)

except Exception as e:
print(e)

finally:
if client_id:
del clients[client_id]

if client_id in peermap:
del peermap[client_id]

if destination_id:
destination_websocket = clients.get(destination_id)

if destination_websocket:
await sendResponse(websocket, client_id, "bye")

if destination_id in peermap:
del peermap[destination_id]

print('Client {} disconnected'.format(client_id))


async def main():
# Usage: ./server.py [[host:]port] [SSL certificate file]
endpoint_or_port = sys.argv[1] if len(sys.argv) > 1 else "8000"
ssl_cert = sys.argv[2] if len(sys.argv) > 2 else None

endpoint = endpoint_or_port if ':' in endpoint_or_port else "127.0.0.1:" + endpoint_or_port

if ssl_cert:
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
ssl_context.load_cert_chain(ssl_cert)
else:
ssl_context = None

print('Listening on {}'.format(endpoint))
host, port = endpoint.rsplit(':', 1)

server = await websockets.serve(handle_websocket, host, int(port), ssl=ssl_context)
await server.wait_closed()


if __name__ == '__main__':
asyncio.run(main())
26 changes: 26 additions & 0 deletions examples/videocall/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
cmake_minimum_required(VERSION 3.7)
if(POLICY CMP0079)
cmake_policy(SET CMP0079 NEW)
endif()

set(VIDEOCALL_SOURCES
main.cpp
dispatchqueue.cpp
helpers.cpp
)

if(CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
message(error, "not supported")
else()
add_executable(videocall ${VIDEOCALL_SOURCES})
endif()

set_target_properties(videocall PROPERTIES
CXX_STANDARD 17
OUTPUT_NAME videocall)

set_target_properties(videocall PROPERTIES
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER com.github.paullouisageneau.libdatachannel.examples.videocall)

find_package(Threads REQUIRED)
target_link_libraries(videocall LibDataChannel::LibDataChannel Threads::Threads nlohmann_json::nlohmann_json)
22 changes: 22 additions & 0 deletions examples/videocall/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from flask import Flask, render_template
import sys

app = Flask(__name__, static_url_path='', static_folder='static')

@app.route('/')
def root():
return render_template('index.html')


if __name__ == '__main__':

address = '127.0.0.1'
port = '5566'

if len(sys.argv) == 3:
address = sys.argv[1]
port = sys.argv[2]

print("server running at ", address, port)

app.run(debug=True, host=address, port=port)
85 changes: 85 additions & 0 deletions examples/videocall/dispatchqueue.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/**
* libdatachannel streamer example
* Copyright (c) 2020 Filip Klembara (in2core)
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/


#include "dispatchqueue.hpp"

DispatchQueue::DispatchQueue(std::string name, size_t threadCount) :
name{std::move(name)}, threads(threadCount) {
for(size_t i = 0; i < threads.size(); i++)
{
threads[i] = std::thread(&DispatchQueue::dispatchThreadHandler, this);
}
}

DispatchQueue::~DispatchQueue() {
// Signal to dispatch threads that it's time to wrap up
std::unique_lock<std::mutex> lock(lockMutex);
quit = true;
lock.unlock();
condition.notify_all();

// Wait for threads to finish before we exit
for(size_t i = 0; i < threads.size(); i++)
{
if(threads[i].joinable())
{
threads[i].join();
}
}
}

void DispatchQueue::removePending() {
std::unique_lock<std::mutex> lock(lockMutex);
queue = {};
}

void DispatchQueue::dispatch(const fp_t& op) {
std::unique_lock<std::mutex> lock(lockMutex);
queue.push(op);

// Manual unlocking is done before notifying, to avoid waking up
// the waiting thread only to block again (see notify_one for details)
lock.unlock();
condition.notify_one();
}

void DispatchQueue::dispatch(fp_t&& op) {
std::unique_lock<std::mutex> lock(lockMutex);
queue.push(std::move(op));

// Manual unlocking is done before notifying, to avoid waking up
// the waiting thread only to block again (see notify_one for details)
lock.unlock();
condition.notify_one();
}

void DispatchQueue::dispatchThreadHandler(void) {
std::unique_lock<std::mutex> lock(lockMutex);
do {
//Wait until we have data or a quit signal
condition.wait(lock, [this]{
return (queue.size() || quit);
});

//after wait, we own the lock
if(!quit && queue.size())
{
auto op = std::move(queue.front());
queue.pop();

//unlock now that we're done messing with the queue
lock.unlock();

op();

lock.lock();
}
} while (!quit);
}
51 changes: 51 additions & 0 deletions examples/videocall/dispatchqueue.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* libdatachannel streamer example
* Copyright (c) 2020 Filip Klembara (in2core)
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

#ifndef dispatchqueue_hpp
#define dispatchqueue_hpp

#include <thread>
#include <mutex>
#include <condition_variable>
#include <queue>
#include <functional>
#include <string>

class DispatchQueue {
typedef std::function<void(void)> fp_t;

public:
DispatchQueue(std::string name, size_t threadCount = 1);
~DispatchQueue();

// dispatch and copy
void dispatch(const fp_t& op);
// dispatch and move
void dispatch(fp_t&& op);

void removePending();

// Deleted operations
DispatchQueue(const DispatchQueue& rhs) = delete;
DispatchQueue& operator=(const DispatchQueue& rhs) = delete;
DispatchQueue(DispatchQueue&& rhs) = delete;
DispatchQueue& operator=(DispatchQueue&& rhs) = delete;

private:
std::string name;
std::mutex lockMutex;
std::vector<std::thread> threads;
std::queue<fp_t> queue;
std::condition_variable condition;
bool quit = false;

void dispatchThreadHandler(void);
};

#endif /* dispatchqueue_hpp */
Loading
Loading