WEBRTC TURNSERVER配置



如何让WEBRTC 支持P2P RELAY

一:下载
libevent下载
http://libevent.org/
turnserver下载
https://github.com/coturn/coturn  new
https://github.com/freewebsys/rfc5766-turn-server old
二:配置
添加用户密码
1. 直接修改 turnuserdb.conf
   添加一行 sjz:111111
2. turnadmin 工具生成 会提示生成到哪个文件
   turnadmin -a -u baoyu -r by -p 111111  
   生成用户和秘钥
   hxy:0xcb39d7e60e8b6e4e98b12a93f2f32bf1
  注意: 0x 为秘钥 没有则为密码
  WEBRTC中只支持密码
  eg:
  webrtc::PeerConnectionInterface::RTCConfiguration config;
  webrtc::PeerConnectionInterface::IceServer server;
  server.urls.push_back("stun:192.168.1.116");
  server.urls.push_back("turn:192.168.1.116");
  server.username = "baoyu";
  server.password = "111111";
  config.servers.push_back(server); 

列车所有用户
 turnadmin -l
 
服务器启动
turnserver -v  -r by  (-r 的参数必须与之前turnadmin 中的 -r 参数一致)
也可在命令行中传递用户和密码
./turnserver -v --user=hxy:111111 --user=sjz:111111 -r by

三:配置WEBRTC 强制RELAY
google WebRTC - how to set always to use TURN server?
http://stackoverflow.com/questions/22130311/webrtc-how-to-set-always-to-use-turn-server
修改参数
  webrtc::PeerConnectionInterface::RTCConfiguration config;
  webrtc::PeerConnectionInterface::IceServer server;
  server.urls.push_back("stun:192.168.1.116");
  server.urls.push_back("turn:192.168.1.116");
  server.username = "baoyu";
  server.password = "111111";
  config.type = webrtc::PeerConnectionInterface::kRelay;
  config.servers.push_back(server);

========================================运行日志===============================
turnuser.db
hxy:0xcb39d7e60e8b6e4e98b12a93f2f32bf1
baoyu:111111

root@ubuntu:~# ./turnserver -v -r by
0: log file opened: /var/log/turn_24305_2016-07-14.log
0:
RFC 3489/5389/5766/5780/6062/6156 STUN/TURN Server
Version Citrix-3.2.5.9 'Marshal West'
0:
Max number of open files/sockets allowed for this process: 65536
0:
Due to the open files/sockets limitation,
max supported number of TURN Sessions possible is: 32500 (approximately)
0:

==== Show him the instruments, Practical Frost: ====

0: TLS supported
0: DTLS supported
0: Redis is not supported
0: PostgreSQL is not supported
0: MySQL is not supported
0: OpenSSL compile-time version 0x1000207f: fresh enough
0: Default Net Engine version: 3 (UDP thread per CPU core)

=====================================================

0: Config file found: /root/turnserver.conf
0: Config file found: /root/turnserver.conf
0: Config file found: /root/turnuserdb.conf
0:
CONFIGURATION ALERT: you specified long-term user accounts, (-u option)
 but you did not specify the long-term credentials option
 (-a or --lt-cred-mech option).
  I am turning --lt-cred-mech ON for you, but double-check your configuration.
0: WARNING: cannot find certificate file: turn_server_cert.pem (1)
0: WARNING: cannot start TLS and DTLS listeners because certificate file is not set properly
0: WARNING: cannot find private key file: turn_server_pkey.pem (1)
0: WARNING: cannot start TLS and DTLS listeners because private key file is not set properly
0: NO EXPLICIT LISTENER ADDRESS(ES) ARE CONFIGURED
0: ===========Discovering listener addresses: =========
0: Listener address to use: 127.0.0.1
0: Listener address to use: 192.168.1.116
0: Listener address to use: ::1
0: =====================================================
0: Total: 1 'real' addresses discovered
0: =====================================================
0: NO EXPLICIT RELAY ADDRESS(ES) ARE CONFIGURED
0: ===========Discovering relay addresses: =============
0: Relay address to use: 192.168.1.116
0: Relay address to use: ::1
0: =====================================================
0: Total: 2 relay addresses discovered
0: =====================================================
0: pid file created: /var/run/turnserver.pid
0: IO method (main listener thread): epoll (with changelist)
0: Wait for relay ports initialization...
0:   relay 192.168.1.116 initialization...
0:   relay 192.168.1.116 initialization done
0:   relay ::1 initialization...
0:   relay ::1 initialization done
0: Relay ports initialization done
0: IO method (general relay thread): epoll (with changelist)
0: turn server id=0 created
0: IPv4. TCP listener opened on : 127.0.0.1:3478
0: IPv4. TCP listener opened on : 127.0.0.1:3479
0: IPv4. TCP listener opened on : 192.168.1.116:3478
0: IPv4. TCP listener opened on : 192.168.1.116:3479
0: IPv6. TCP listener opened on : ::1:3478
0: IPv6. TCP listener opened on : ::1:3479
0: IO method (general relay thread): epoll (with changelist)
0: turn server id=1 created
0: IPv4. UDP listener opened on: 127.0.0.1:3478
0: IPv4. TCP listener opened on : 127.0.0.1:3478
0: IPv4. UDP listener opened on: 127.0.0.1:3479
0: IPv4. UDP listener opened on: 192.168.1.116:3478
0: IPv4. UDP listener opened on: 192.168.1.116:3479
0: IPv6. UDP listener opened on: ::1:3478
0: IPv4. TCP listener opened on : 127.0.0.1:3479
0: IPv4. TCP listener opened on : 192.168.1.116:3478
0: IPv4. TCP listener opened on : 192.168.1.116:3479
0: IPv6. TCP listener opened on : ::1:3478
0: IPv6. TCP listener opened on : ::1:3479
0: IPv6. UDP listener opened on: ::1:3479
0: Total UDP servers: 0
0: Total General servers: 2
0: IO method (auth thread): epoll (with changelist)
0: IO method (cli thread): epoll (with changelist)
0: IPv4. CLI listener opened on : 127.0.0.1:5766
3: handle_udp_packet: New UDP endpoint: local addr 192.168.1.116:3478, remote addr 192.168.1.113:53129
3: session 001000000000000001: user <>: incoming packet BINDING processed, success
3: handle_udp_packet: New UDP endpoint: local addr 192.168.1.116:3478, remote addr 192.168.1.113:53131
3: session 001000000000000002: user <>: incoming packet BINDING processed, success
3: handle_udp_packet: New UDP endpoint: local addr 192.168.1.116:3478, remote addr 192.168.1.113:53133
3: session 001000000000000003: user <>: incoming packet BINDING processed, success
3: handle_udp_packet: New UDP endpoint: local addr 192.168.1.116:3478, remote addr 192.168.1.113:53135
3: session 001000000000000004: user <>: incoming packet BINDING processed, success
4: session 001000000000000001: user <>: incoming packet message processed, error 401: Unauthorised
4: session 001000000000000002: user <>: incoming packet message processed, error 401: Unauthorised
4: session 001000000000000003: user <>: incoming packet message processed, error 401: Unauthorised
4: session 001000000000000004: user <>: incoming packet message processed, error 401: Unauthorised
4: IPv4. Local relay addr: 192.168.1.116:63300
4: session 001000000000000001: new, username=<baoyu>, lifetime=600
4: session 001000000000000001: user <baoyu>: incoming packet ALLOCATE processed, success
4: IPv4. Local relay addr: 192.168.1.116:53067
4: session 001000000000000002: new, username=<baoyu>, lifetime=600
4: session 001000000000000002: user <baoyu>: incoming packet ALLOCATE processed, success
4: IPv4. Local relay addr: 192.168.1.116:49434
4: session 001000000000000003: new, username=<baoyu>, lifetime=600
4: session 001000000000000003: user <baoyu>: incoming packet ALLOCATE processed, success
4: IPv4. Local relay addr: 192.168.1.116:63580
4: session 001000000000000004: new, username=<baoyu>, lifetime=600
4: session 001000000000000004: user <baoyu>: incoming packet ALLOCATE processed, success
4: handle_udp_packet: New UDP endpoint: local addr 192.168.1.116:3478, remote addr 192.168.1.226:59724
4: session 000000000000000001: user <>: incoming packet BINDING processed, success
4: session 001000000000000004: refreshed, username=<baoyu>, lifetime=0
4: session 001000000000000004: user <baoyu>: incoming packet REFRESH processed, success
4: session 001000000000000003: refreshed, username=<baoyu>, lifetime=0
4: session 001000000000000003: user <baoyu>: incoming packet REFRESH processed, success
4: session 001000000000000002: refreshed, username=<baoyu>, lifetime=0
4: session 001000000000000002: user <baoyu>: incoming packet REFRESH processed, success
4: session 000000000000000001: user <>: incoming packet message processed, error 401: Unauthorised
4: IPv4. Local relay addr: 192.168.1.116:63258
4: session 000000000000000001: new, username=<hxy>, lifetime=600
4: session 000000000000000001: user <hxy>: incoming packet ALLOCATE processed, success
4: session 000000000000000001: peer 192.168.1.116 lifetime updated: 300
4: session 000000000000000001: user <hxy>: incoming packet CREATE_PERMISSION processed, success
4: session 001000000000000001: peer 192.168.1.116 lifetime updated: 300
4: session 001000000000000001: user <baoyu>: incoming packet CREATE_PERMISSION processed, success
4: session 001000000000000001: peer 192.168.1.116 lifetime updated: 600
4: session 001000000000000001: user <baoyu>: incoming packet CHANNEL_BIND processed, success
4: session 000000000000000001: peer 192.168.1.116 lifetime updated: 600
4: session 000000000000000001: user <hxy>: incoming packet CHANNEL_BIND processed, success
5: session 001000000000000004: closed (2nd stage), user <baoyu>, local 192.168.1.116:3478, remote 192.168.1.113:53135, reason: allocation timeout
5: session 001000000000000003: closed (2nd stage), user <baoyu>, local 192.168.1.116:3478, remote 192.168.1.113:53133, reason: allocation timeout
5: session 001000000000000002: closed (2nd stage), user <baoyu>, local 192.168.1.116:3478, remote 192.168.1.113:53131, reason: allocation timeout
5: session 000000000000000001: usage: username=<hxy>, rp=55, rb=2872, sp=1993, sb=1354716
5: session 001000000000000001: usage: username=<baoyu>, rp=1994, rb=1355013, sp=54, sb=2864
6: session 000000000000000001: usage: username=<hxy>, rp=49, rb=2220, sp=1999, sb=1165526
6: session 001000000000000001: usage: username=<baoyu>, rp=1999, rb=1165526, sp=49, sb=2220
7: session 001000000000000001: usage: username=<baoyu>, rp=2010, rb=1177357, sp=38, sb=1796
7: session 000000000000000001: usage: username=<hxy>, rp=38, rb=1796, sp=2010, sb=1177359
8: session 001000000000000001: usage: username=<baoyu>, rp=2010, rb=1260380, sp=38, sb=1780
8: session 000000000000000001: usage: username=<hxy>, rp=38, rb=1780, sp=2010, sb=1260380
9: session 000000000000000001: usage: username=<hxy>, rp=43, rb=2112, sp=2005, sb=1150734
9: session 001000000000000001: usage: username=<baoyu>, rp=2005, rb=1149884, sp=43, sb=2112



评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值