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

uTP Client Interop #74

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
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
34 changes: 34 additions & 0 deletions utp-client-interop/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# r - means run
# rxy - x means which language c=c r=rust n=nim
# rxy - y is either recv or send which will either setup the library to receive data or send it
# goal? as tooling is built up till it will possibly allow for test automation?

# instructions run a recv then a sender

rcrecv:
cd libutp && make
./libutp/ucat-static -ddddd -l -p 9078

rcsend:
cd libutp && make
./libutp/portal-test

rrsend:
cd rust-utp && RUST_LOG=trace cargo run -- send

rrrecv:
cd rust-utp && RUST_LOG=trace cargo run -- recv

rnsend:
cd nim-utp && nimble c src/send.nim
./nim-utp/src/send

# currently doesn't work I need to understand nim syntax more
rnrecv:
cd nim-utp && nimble c src/recv.nim
./nim-utp/src/recv

clean:
rm nim-utp/src/send nim-utp/src/recv -f
rm rust-utp/target -rf
cd libutp && make clean
41 changes: 41 additions & 0 deletions utp-client-interop/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# utp interop testing

if you are trying to use C, Rust, Nim's client it will be assumed you have there respective development depends installed.

### Test ethereum/utp send to bittorrent/libutp

Terminal 1
```
make rcrecv
```

Terminal 2
```
make rrsend
```

### Test bittorrent/libutp send to ethereum/utp

Terminal 1
```
make rrrecv
```

Terminal 2
```
make rcsend
```

### Test bittorrent/libutp send to bittorrent/libutp

Terminal 1
```
make rcrecv
```

Terminal 2
```
make rcsend
```

### etc, etc
19 changes: 19 additions & 0 deletions utp-client-interop/libutp/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2010-2013 BitTorrent, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
51 changes: 51 additions & 0 deletions utp-client-interop/libutp/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
OBJS = utp_internal.o utp_utils.o utp_hash.o utp_callbacks.o utp_api.o utp_packedsockaddr.o
CFLAGS = -Wall -DPOSIX -g -fno-exceptions $(OPT)
OPT ?= -O3
CXXFLAGS = $(CFLAGS) -fPIC -fno-rtti
CC = gcc
CXX = g++

CXXFLAGS += -Wno-sign-compare
CXXFLAGS += -fpermissive

# Uncomment to enable utp_get_stats(), and a few extra sanity checks
#CFLAGS += -D_DEBUG

# Uncomment to enable debug logging
#CFLAGS += -DUTP_DEBUG_LOGGING

# Dynamically determine if librt is available. If so, assume we need to link
# against it for clock_gettime(2). This is required for clean builds on OSX;
# see <https://github.com/bittorrent/libutp/issues/1> for more. This should
# probably be ported to CMake at some point, but is suitable for now.
lrt := $(shell echo 'int main() {}' | $(CC) -xc -o /dev/null - -lrt >/dev/null 2>&1; echo $$?)
ifeq ($(strip $(lrt)),0)
LDFLAGS += -lrt
endif

all: libutp.so libutp.a ucat ucat-static portal-test

libutp.so: $(OBJS)
$(CXX) $(CXXFLAGS) -o libutp.so -shared $(OBJS)

libutp.a: $(OBJS)
ar rvs libutp.a $(OBJS)

ucat: ucat.o libutp.so
$(CC) $(CFLAGS) -o ucat ucat.o -L. -lutp $(LDFLAGS)

ucat-static: ucat.o libutp.a
$(CXX) $(CXXFLAGS) -o ucat-static ucat.o libutp.a $(LDFLAGS)

portal-test: portal-test.o libutp.a
$(CXX) $(CXXFLAGS) -o portal-test portal-test.o libutp.a $(LDFLAGS)

clean:
rm -f *.o libutp.so libutp.a ucat ucat-static portal-test

tags: $(shell ls *.cpp *.h)
rm -f tags
ctags *.cpp *.h

anyway: clean all
.PHONY: clean all anyway
68 changes: 68 additions & 0 deletions utp-client-interop/libutp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# libutp - The uTorrent Transport Protocol library.
Copyright (c) 2010 BitTorrent, Inc.

uTP is a TCP-like implementation of [LEDBAT][ledbat] documented as a BitTorrent
extension in [BEP-29][bep29]. uTP provides reliable, ordered delivery
while maintaining minimum extra delay. It is implemented on top of UDP to be
cross-platform and functional today. As a result, uTP is the primary transport
for uTorrent peer-to-peer connections.

uTP is written in C++, but the external interface is strictly C (ANSI C89).

## The Interface

The uTP socket interface is a bit different from the Berkeley socket API to
avoid the need for our own select() implementation, and to make it easier to
write event-based code with minimal buffering.

When you create a uTP socket, you register a set of callbacks. Most notably, the
on_read callback is a reactive callback which occurs when bytes arrive off the
network. The write side of the socket is proactive, and you call UTP_Write to
indicate the number of bytes you wish to write. As packets are created, the
on_write callback is called for each packet, so you can fill the buffers with
data.

The libutp interface is not thread-safe. It was designed for use in a
single-threaded asyncronous context, although with proper synchronization
it may be used from a multi-threaded environment as well.

See utp.h for more details and other API documentation.

## Example

See ucat.c. Build with:

make ucat

## Building

uTP has been known to build on Windows with MSVC and on linux and OS X with gcc.
On Windows, use the MSVC project files (utp.sln, and friends). On other platforms,
building the shared library is as simple as:

make

To build one of the examples, which will statically link in everything it needs
from libutp:

cd utp_test && make

## Packaging and API

The libutp API is considered unstable, and probably always will be. We encourage
you to test with the version of libutp you have, and be mindful when upgrading.
For this reason, it is probably also a good idea to bundle libutp with your
application.

## License

libutp is released under the [MIT][lic] license.

## Related Work

Research and analysis of congestion control mechanisms can be found [here.][survey]

[ledbat]: http://datatracker.ietf.org/wg/ledbat/charter/
[bep29]: http://www.bittorrent.org/beps/bep_0029.html
[lic]: http://www.opensource.org/licenses/mit-license.php
[survey]: http://datatracker.ietf.org/doc/draft-ietf-ledbat-survey/
65 changes: 65 additions & 0 deletions utp-client-interop/libutp/libutp-2012.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="utp_templates.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="utp_callbacks.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="utp_hash.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="utp_internal.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="utp_packedsockaddr.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="utp_utils.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="utp_types.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="utp.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="libutp_inet_ntop.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="utp_api.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="utp_callbacks.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="utp_hash.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="utp_internal.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="utp_packedsockaddr.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="utp_utils.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="libutp_inet_ntop.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
Loading