이 저장소에는 Cross-Platform C ++ Tubus 라이브러리가 포함되어 있으며 UDP 를 기반으로 한 스트리밍 전송 프로토콜을 구현합니다. 이 프로토콜은 원래 Wormhole 유틸리티의 일부로 개발되었습니다. 예를 들어 NAT를 통해 실행되는 응용 분야에서는 TCP의 사용이 어려운 경우에 사용할 수 있습니다. 선택적으로 연결 보안을 향상시키기 위해 tubus 패킷은 사전 공유 키로 난독 화 될 수 있습니다.
boost::asio 기반으로 응용 프로그램을 개발하는 편의를 위해 Asio와 같은 프리미티브 tubus::socket tubus::acceptor 제공됩니다. tubus::socket Primitive는 AsyncreadStream , Asyncwritestream , Stream , SyncreadStream 및 SynCwriteStream 개념을 구현하므로 boost::asio::ssl::stream 의 하부 층으로 사용할 수 있습니다.
Tubus сhannel 인터페이스.
namespace tubus {
...
struct channel
{
virtual ~channel () noexcept ( true ) {}
virtual void close () noexcept ( true ) = 0;
virtual void open ( const endpoint& local) noexcept ( false ) = 0;
virtual void connect ( const endpoint& remote, const callback& handle) noexcept ( true ) = 0;
virtual void accept ( const endpoint& remote, const callback& handle) noexcept ( true ) = 0;
virtual void read ( const mutable_buffer& buffer, const io_callback& handle) noexcept ( true ) = 0;
virtual void write ( const const_buffer& buffer, const io_callback& handle) noexcept ( true ) = 0;
virtual void shutdown ( const callback& handle) noexcept ( true ) = 0;
virtual size_t writable () const noexcept ( true ) = 0;
virtual size_t readable () const noexcept ( true ) = 0;
virtual endpoint host () const noexcept ( false ) = 0;
virtual endpoint peer () const noexcept ( false ) = 0;
};
...
channel_ptr create_channel (boost::asio::io_context& io, uint64_t /* pre-shared key */ secret = 0 ) noexcept ( true );
} tubus::channel 사용하여 데이터 소비자가 구현되었습니다.
# include < tubus/channel.h >
...
auto consumer = tubus::create_channel(io_service, key);
consumer-> open (local_endpoint);
consumer-> connect (remote_endpoint, [&]( const boost::system::error_code& error)
{
...
tubus::mutable_buffer buffer (consumer-> readable ());
// if the buffer is empty, the callback will be called when all previously
// pended read operations are completed and more data can be read
consumer-> read (buffer, [&]( const boost:: system ::error_code& error, size_t size)
{
...
consumer-> shutdown ();
};
}); 데이터 생산자는 tubus::socket 사용하여 구현되었습니다.
# include < tubus/socket.h >
...
tubus::socket producer (io_service, key);
producer.open(local_endpoint);
producer.async_accept(remote_endpoint, [&]( const boost::system::error_code& error)
{
...
tubus::const_buffer buffer ( " hello, world! " );
producer. async_write_some (buffer, [&]( const boost:: system ::error_code& error, size_t size)
{
...
producer. shutdown ();
};
}); tubus::acceptor ( Linux 만 해당)를 사용하여 구현되었습니다.
# include < tubus/acceptor.h >
...
tubus::acceptor server (io_service, key);
server.open(local_endpoint);
tubus::socket peer1 (io_service);
server.accept(peer1);
peer1.read_some(...);
peer1.write_some(...);
tubus::socket peer2 (io_service);
server.accept(peer2);
peer2.read_some(...);
peer2.write_some(...);
peer1.shutdown();
peer2.shutdown();
server.close(); boost::asio::ssl::stream 및 tubus::socket 사용하여 구현 된 암호화 스트림.
# include < boost/asio/ssl.hpp >
# include < tubus/socket.h >
...
boost::asio::ssl::stream<tubus::socket> client (tubus::socket(io_service, key), ssl_ctx);
client.lowest_layer().open(local_endpoint);
client.lowest_layer().connect(remote_endpoint);
client.handshake(boost::asio::ssl::stream_base::client);
boost::asio::read (client, ...);
boost::asio::write (client, ...);
client.shutdown();Debian 및 Windows 플랫폼 용 Prebuild 패키지를 다운로드 할 수 있습니다.
라이브러리는 boost 에 따라 다릅니다. 테스트를 구축하려면 openssl 이 필요합니다.
cd ~
git clone https://github.com/novemus/tubus.git
cd ~/tubus
cmake -B ./build [-DBOOST_ROOT=...] [-DBUILD_TESTING=ON [-DOPENSSL_ROOT_DIR=...]]
cmake --build ./build --config Release --target tubus_shared tubus_static [tubus_ut]
cmake --build ./build --target install CMake 가져 오기 변수.
버그를보고하고 개선을 제안합니다.
Tubus는 Apache License 2.0에 따라 라이센스가 부여되므로 조건을 충족하는 한 상업적 및 비상업적 목적으로 자유롭게 사용할 수 있습니다. 자세한 내용은 License.txt 파일을 참조하십시오.
Copyright © 2023 Novemus Band. 모든 권리 보유.