LoginSignup
2
0

More than 1 year has passed since last update.

Tsunami UDP Protocolを動かしてみた

Last updated at Posted at 2021-12-22

この記事は NTTコムウェア Advent Calendar 2021 22日目の記事です。

はじめに

この記事はAmazon Web Services クラウドデザインパターン 実装ガイド[改訂版]の第3章で紹介されていたTsunami UDP Protocolを動かしてみたという内容になります。
私の環境ではビルドする際にエラーになったので、同じような状況になった人の助けになれば幸いです。

Tsunami UDP Protocolとは

TCPとUDPを利用したファイル転送プロトコルです。TCPよりも高速です。
大規模なファイル転送に向いています。

環境情報

クライアント

macOS Mojave(バージョン 10.14.6)

サーバ

Amazon Linux release 2 (Karoo)

Tsunami UDP Protocolのインストール方法

ダウンロード

以下のページにアクセスしてDownloadボタンをクリックしましょう

https://sourceforge.net/projects/tsunami-udp/

ダウンロードできたら解凍します。

tar xzvf tsunami-v1.1-cvsbuild42.tar.gz

ライブラリのインストール

このソフトはクライアントとサーバ両方にインストールする必要があります。

macの場合

gccはインストール済みとします。

brew install make
brew install autoconf
brew install automake

Linuxの場合

sudo yum install make
sudo yum install gcc
sudo yum install autoconf
sudo yum install automake

ビルドとインストール

cd tsunami-udp-v11-b42/
aclocal
autoconf
automake
./configure
make
sudo make install

automakeのところでエラーが発生します。

configure.in:51: error: required file './compile' not found
configure.in:51:   'automake --add-missing' can install 'compile'

compileファイルがないので、以下のコマンドでインストールします

automake --add-missing

automakeは通りましたが、
次はmakeで以下のエラーが発生します。

In file included from common.c:73:
../include/tsunami.h:141:12: error: expected ')'
u_int64_t  htonll                  (u_int64_t value);
           ^
In file included from common.c:73:
../include/tsunami.h:141:12: error: cannot redeclare builtin function '__builtin_constant_p'
u_int64_t  htonll                  (u_int64_t value);
           ^
In file included from common.c:73:
../include/tsunami.h:143:12: error: expected ')'
u_int64_t  ntohll                  (u_int64_t value);
           ^
In file included from common.c:73:
../include/tsunami.h:143:12: error: cannot redeclare builtin function '__builtin_constant_p'
u_int64_t  ntohll                  (u_int64_t value);
           ^
common.c:149:11: error: expected ')'
u_int64_t htonll(u_int64_t value)
          ^
common.c:149:11: error: cannot redeclare builtin function '__builtin_constant_p'
u_int64_t htonll(u_int64_t value)
          ^
common.c:149:11: error: definition of builtin function '__builtin_constant_p'
u_int64_t htonll(u_int64_t value)
          ^
common.c:194:11: error: expected ')'
u_int64_t ntohll(u_int64_t value)
          ^
common.c:194:11: error: cannot redeclare builtin function '__builtin_constant_p'
u_int64_t ntohll(u_int64_t value)
          ^
common.c:194:11: error: definition of builtin function '__builtin_constant_p'
u_int64_t ntohll(u_int64_t value)
          ^
10 errors generated.

common.cのntohllとhtonllの関数でエラーが発生しているのでコメントアウトします。

sed -i .bak -e '149,162s:^:\/\/ :' -e '194,197s:^:\/\/ :' ./common/common.c

tsunami.hのntohllとhtonllの関数でエラーが発生しているのでコメントアウトします。

sed -i .bak -e '141s:^:\/\/ :'  -e '143s:^:\/\/ :' ./include/tsunami.h

これでいけたと思いきやまたもやエラーが発生します。

gcc  -g -Wall -O3 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64   -o tsunami command.o config.o io.o main.o network.o protocol.o ring.o transcript.o ../common/libtsunami_common.a -lpthread 
Undefined symbols for architecture x86_64:
  "_got_block", referenced from:
      _ttp_repeat_retransmit in protocol.o
      _ttp_request_retransmit in protocol.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

調べてみると、インライン関数のコンパイル?で失敗しているようなので、インライン関数を削除します。

sed -i .bak -e '242s:inline ::' ./include/tsunami-client.h

やっとエラーがなくなりました。

make[1]: Nothing to be done for `all-am'.

You can do a 'sudo make install' to install binaries into /usr/bin

これでmake installすればインストール完了です。

動作確認

Tsunami UDPはデフォルトで46224番ポートを使用するので、事前にルーターの46224番ポートを開放しておく必要があります。

クライアント側

$ tsunamid 150x150.png 

The specified 1 files will be listed on GET *:
   1)   150x150.png           864 bytes
total characters 12
Block size: 1024
Buffer size: 20000000
Port: 46224
Tsunami Server for protocol rev 20061025
Revision: v1.1 devel cvsbuild 42
Compiled: Dec 19 2021 13:46:56
Waiting for clients to connect.
New client connecting from 13.113.174.157...
Client authenticated. Negotiated parameters are:
Block size: 1024
Buffer size: 20000000
Port: 46224
Request for file: '150x150.png'
Sending to client port 46224
Warning: Error in resizing UDP transmit buffer
Transmission complete.
Server 1 transferred 864 bytes in 0.01 seconds (0.9 Mbps)

サーバ側

$ tsunami
Tsunami Client for protocol rev 20061025
Revision: v1.1 devel cvsbuild 42
Compiled: Jul  3 2021 10:13:35
tsunami> connect xxx.xxx.xxx.xxx      
Connected.

tsunami> get 150x150.png        
Receiving data on UDP port 46224
Transfer complete. Flushing to disk and signaling server to stop...
!!!!
PC performance figure : 0 packets dropped (if high this indicates receiving PC overload)
Transfer duration     : 0.01 seconds
Total packet data     : 0.01 Mbit
Goodput data          : 0.01 Mbit
File data             : 0.01 Mbit
Throughput            : 1.05 Mbps
Goodput w/ restarts   : 1.05 Mbps
Final file rate       : 0.89 Mbps
Transfer mode         : lossless

あとがき

なんとかTsunami UDP Protocolの動作を確認することができました。
今回エラーが出たものを取り除くというエンジニアらしからぬ?強引な方法で動作させました。
本当は適切なコードに書き換えたかったのですが、自分の今の実力では無理でした。
C言語に自信のある方は是非エラーの箇所を適切なコードに書き換えてみてください!

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0