mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-11 16:32:59 +00:00
Bug 891551 - Part 11: fix a couple of issues from part 5. r=bwc
This commit is contained in:
parent
ce7a04b4f0
commit
2e746f9a3a
@ -533,7 +533,8 @@ int NrSocket::create(nr_transport_addr *addr) {
|
||||
opt_reuseaddr.value.reuse_addr = PR_TRUE;
|
||||
status = PR_SetSocketOption(fd_, &opt_reuseaddr);
|
||||
if (status != PR_SUCCESS) {
|
||||
r_log(LOG_GENERIC, LOG_CRIT, "Couldn't set reuse addr socket option");
|
||||
r_log(LOG_GENERIC, LOG_CRIT,
|
||||
"Couldn't set reuse addr socket option: %d", status);
|
||||
ABORT(R_INTERNAL);
|
||||
}
|
||||
// And also set ReusePort for platforms supporting this socket option
|
||||
@ -543,10 +544,20 @@ int NrSocket::create(nr_transport_addr *addr) {
|
||||
status = PR_SetSocketOption(fd_, &opt_reuseport);
|
||||
if (status != PR_SUCCESS) {
|
||||
if (PR_GetError() != PR_OPERATION_NOT_SUPPORTED_ERROR) {
|
||||
r_log(LOG_GENERIC, LOG_CRIT, "Couldn't set reuse port socket option");
|
||||
r_log(LOG_GENERIC, LOG_CRIT,
|
||||
"Couldn't set reuse port socket option: %d", status);
|
||||
ABORT(R_INTERNAL);
|
||||
}
|
||||
}
|
||||
// Try to speedup packet delivery by disabling TCP Nagle
|
||||
PRSocketOptionData opt_nodelay;
|
||||
opt_nodelay.option = PR_SockOpt_NoDelay;
|
||||
opt_nodelay.value.no_delay = PR_TRUE;
|
||||
status = PR_SetSocketOption(fd_, &opt_nodelay);
|
||||
if (status != PR_SUCCESS) {
|
||||
r_log(LOG_GENERIC, LOG_WARNING,
|
||||
"Couldn't set Nodelay socket option: %d", status);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ABORT(R_INTERNAL);
|
||||
@ -820,45 +831,59 @@ int NrSocket::accept(nr_transport_addr *addrp, nr_socket **sockp) {
|
||||
ASSERT_ON_THREAD(ststhread_);
|
||||
int _status, r;
|
||||
PRStatus status;
|
||||
PRFileDesc *ret;
|
||||
PRFileDesc *prfd;
|
||||
PRNetAddr nfrom;
|
||||
NrSocket *sock=nullptr;
|
||||
nsresult rv;
|
||||
PRSocketOptionData opt_nonblock, opt_nodelay;
|
||||
nsCOMPtr<nsISocketTransportService> stservice =
|
||||
do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv);
|
||||
PRSocketOptionData option;
|
||||
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
ABORT(R_INTERNAL);
|
||||
}
|
||||
|
||||
assert(fd_);
|
||||
ret = PR_Accept(fd_, &nfrom, PR_INTERVAL_NO_WAIT);
|
||||
if(!fd_)
|
||||
ABORT(R_EOD);
|
||||
|
||||
if (!ret) {
|
||||
prfd = PR_Accept(fd_, &nfrom, PR_INTERVAL_NO_WAIT);
|
||||
|
||||
if (!prfd) {
|
||||
if (PR_GetError() == PR_WOULD_BLOCK_ERROR)
|
||||
ABORT(R_WOULDBLOCK);
|
||||
|
||||
ABORT(R_IO_ERROR);
|
||||
}
|
||||
|
||||
if((r=nr_praddr_to_transport_addr(&nfrom,addrp,my_addr_.protocol,0)))
|
||||
ABORT(r);
|
||||
|
||||
sock = new NrSocket();
|
||||
|
||||
sock->fd_=ret;
|
||||
sock->fd_=prfd;
|
||||
nr_transport_addr_copy(&sock->my_addr_, &my_addr_);
|
||||
|
||||
if((r=nr_praddr_to_transport_addr(&nfrom, addrp, my_addr_.protocol, 0)))
|
||||
ABORT(r);
|
||||
|
||||
// Set nonblocking
|
||||
option.option = PR_SockOpt_Nonblocking;
|
||||
option.value.non_blocking = PR_TRUE;
|
||||
status = PR_SetSocketOption(ret, &option);
|
||||
opt_nonblock.option = PR_SockOpt_Nonblocking;
|
||||
opt_nonblock.value.non_blocking = PR_TRUE;
|
||||
status = PR_SetSocketOption(prfd, &opt_nonblock);
|
||||
if (status != PR_SUCCESS) {
|
||||
r_log(LOG_GENERIC, LOG_CRIT, "Couldn't make socket nonblocking");
|
||||
r_log(LOG_GENERIC, LOG_CRIT,
|
||||
"Failed to make accepted socket nonblocking: %d", status);
|
||||
ABORT(R_INTERNAL);
|
||||
}
|
||||
// Disable TCP Nagle
|
||||
opt_nodelay.option = PR_SockOpt_NoDelay;
|
||||
opt_nodelay.value.no_delay = PR_TRUE;
|
||||
status = PR_SetSocketOption(prfd, &opt_nodelay);
|
||||
if (status != PR_SUCCESS) {
|
||||
r_log(LOG_GENERIC, LOG_WARNING,
|
||||
"Failed to set Nodelay on accepted socket: %d", status);
|
||||
}
|
||||
|
||||
// Should fail only with OOM
|
||||
if ((r=nr_socket_create_int(static_cast<void *>(sock), sock->vtbl(), sockp)))
|
||||
ABORT(r);
|
||||
|
||||
// Remember our thread.
|
||||
sock->ststhread_ = do_QueryInterface(stservice, &rv);
|
||||
@ -866,18 +891,13 @@ int NrSocket::accept(nr_transport_addr *addrp, nr_socket **sockp) {
|
||||
ABORT(R_INTERNAL);
|
||||
|
||||
// Finally, register with the STS
|
||||
rv = stservice->AttachSocket(ret, sock);
|
||||
rv = stservice->AttachSocket(prfd, sock);
|
||||
if (NS_FAILED(rv)) {
|
||||
ABORT(R_INTERNAL);
|
||||
}
|
||||
|
||||
sock->connect_invoked_ = true;
|
||||
|
||||
r = nr_socket_create_int(static_cast<void *>(sock),
|
||||
sock->vtbl(), sockp);
|
||||
if (r)
|
||||
ABORT(r);
|
||||
|
||||
// Add a reference so that we can delete it in destroy()
|
||||
sock->AddRef();
|
||||
_status=0;
|
||||
|
@ -1135,8 +1135,8 @@ class IceGatherTest : public ::testing::Test {
|
||||
ASSERT_TRUE_WAIT(peer_->gathering_complete(), waitTime);
|
||||
}
|
||||
|
||||
void UseFakeStunServerWithResponse(const std::string& fake_addr,
|
||||
uint16_t fake_port) {
|
||||
void UseFakeStunUdpServerWithResponse(const std::string& fake_addr,
|
||||
uint16_t fake_port) {
|
||||
EnsurePeer();
|
||||
TestStunServer::GetInstance()->SetResponseAddr(fake_addr, fake_port);
|
||||
// Sets an additional stun server
|
||||
@ -1586,7 +1586,8 @@ TEST_F(IceGatherTest, TestGatherFakeStunServerTcpHostnameNoResolver) {
|
||||
}
|
||||
|
||||
EnsurePeer();
|
||||
peer_->SetStunServer(g_stun_server_hostname, kDefaultStunServerPort, kNrIceTransportTcp);
|
||||
peer_->SetStunServer(g_stun_server_hostname, kDefaultStunServerPort,
|
||||
kNrIceTransportTcp);
|
||||
Gather();
|
||||
}
|
||||
|
||||
@ -1632,6 +1633,10 @@ TEST_F(IceGatherTest, TestGatherDNSStunServerIpAddress) {
|
||||
}
|
||||
|
||||
TEST_F(IceGatherTest, TestGatherDNSStunServerIpAddressTcp) {
|
||||
if (g_stun_server_address.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
EnsurePeer();
|
||||
peer_->SetStunServer(g_stun_server_address, kDefaultStunServerPort,
|
||||
kNrIceTransportTcp);
|
||||
@ -1659,6 +1664,10 @@ TEST_F(IceGatherTest, TestGatherDNSStunServerHostnameTcp) {
|
||||
}
|
||||
|
||||
TEST_F(IceGatherTest, TestGatherDNSStunServerHostnameBothUdpTcp) {
|
||||
if (g_stun_server_hostname.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<NrIceStunServer> stun_servers;
|
||||
|
||||
EnsurePeer();
|
||||
@ -1672,6 +1681,10 @@ TEST_F(IceGatherTest, TestGatherDNSStunServerHostnameBothUdpTcp) {
|
||||
}
|
||||
|
||||
TEST_F(IceGatherTest, TestGatherDNSStunServerIpAddressBothUdpTcp) {
|
||||
if (g_stun_server_address.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<NrIceStunServer> stun_servers;
|
||||
|
||||
EnsurePeer();
|
||||
@ -1766,7 +1779,7 @@ TEST_F(IceGatherTest, TestBogusCandidate) {
|
||||
}
|
||||
|
||||
TEST_F(IceGatherTest, VerifyTestStunServer) {
|
||||
UseFakeStunServerWithResponse("192.0.2.133", 3333);
|
||||
UseFakeStunUdpServerWithResponse("192.0.2.133", 3333);
|
||||
Gather();
|
||||
ASSERT_TRUE(StreamHasMatchingCandidate(0, " 192.0.2.133 3333 "));
|
||||
}
|
||||
@ -1774,29 +1787,30 @@ TEST_F(IceGatherTest, VerifyTestStunServer) {
|
||||
TEST_F(IceGatherTest, VerifyTestStunTcpServer) {
|
||||
UseFakeStunTcpServerWithResponse("192.0.2.233", 3333);
|
||||
Gather();
|
||||
ASSERT_TRUE(StreamHasMatchingCandidate(0, " 192.0.2.233 3333 typ srflx", " tcptype "));
|
||||
ASSERT_TRUE(StreamHasMatchingCandidate(0, " 192.0.2.233 3333 typ srflx",
|
||||
" tcptype "));
|
||||
}
|
||||
|
||||
TEST_F(IceGatherTest, TestStunServerReturnsWildcardAddr) {
|
||||
UseFakeStunServerWithResponse("0.0.0.0", 3333);
|
||||
UseFakeStunUdpServerWithResponse("0.0.0.0", 3333);
|
||||
Gather(kDefaultTimeout * 3);
|
||||
ASSERT_FALSE(StreamHasMatchingCandidate(0, " 0.0.0.0 "));
|
||||
}
|
||||
|
||||
TEST_F(IceGatherTest, TestStunServerReturnsPort0) {
|
||||
UseFakeStunServerWithResponse("192.0.2.133", 0);
|
||||
UseFakeStunUdpServerWithResponse("192.0.2.133", 0);
|
||||
Gather(kDefaultTimeout * 3);
|
||||
ASSERT_FALSE(StreamHasMatchingCandidate(0, " 192.0.2.133 0 "));
|
||||
}
|
||||
|
||||
TEST_F(IceGatherTest, TestStunServerReturnsLoopbackAddr) {
|
||||
UseFakeStunServerWithResponse("127.0.0.133", 3333);
|
||||
UseFakeStunUdpServerWithResponse("127.0.0.133", 3333);
|
||||
Gather(kDefaultTimeout * 3);
|
||||
ASSERT_FALSE(StreamHasMatchingCandidate(0, " 127.0.0.133 "));
|
||||
}
|
||||
|
||||
TEST_F(IceGatherTest, TestStunServerTrickle) {
|
||||
UseFakeStunServerWithResponse("192.0.2.1", 3333);
|
||||
UseFakeStunUdpServerWithResponse("192.0.2.1", 3333);
|
||||
TestStunServer::GetInstance()->SetActive(false);
|
||||
Gather(0);
|
||||
ASSERT_FALSE(StreamHasMatchingCandidate(0, "192.0.2.1"));
|
||||
|
@ -121,7 +121,7 @@ class MultiTcpSocketTest : public ::testing::Test {
|
||||
}
|
||||
|
||||
ASSERT_EQ(0, r);
|
||||
printf("Created socket on %s\n", local.as_string);
|
||||
printf("Creating socket on %s\n", local.as_string);
|
||||
r = nr_socket_multi_tcp_set_readable_cb(*sock,
|
||||
&MultiTcpSocketTest::SockReadable, this);
|
||||
ASSERT_EQ(0, r);
|
||||
@ -143,7 +143,7 @@ class MultiTcpSocketTest : public ::testing::Test {
|
||||
nr_transport_addr addr;
|
||||
int r=nr_socket_getaddr(sock, &addr);
|
||||
ASSERT_EQ(0, r);
|
||||
printf("Listen on %s\n", addr.as_string);
|
||||
printf("Listening on %s\n", addr.as_string);
|
||||
r = nr_socket_listen(sock, 5);
|
||||
ASSERT_EQ(0, r);
|
||||
}
|
||||
@ -162,7 +162,7 @@ class MultiTcpSocketTest : public ::testing::Test {
|
||||
ASSERT_EQ(0, r);
|
||||
r=nr_socket_getaddr(from, &addr_from);
|
||||
ASSERT_EQ(0, r);
|
||||
printf("Connect from %s to %s\n", addr_from.as_string, addr_to.as_string);
|
||||
printf("Connecting from %s to %s\n", addr_from.as_string, addr_to.as_string);
|
||||
r=nr_socket_connect(from, &addr_to);
|
||||
ASSERT_EQ(0, r);
|
||||
}
|
||||
@ -181,7 +181,7 @@ class MultiTcpSocketTest : public ::testing::Test {
|
||||
ASSERT_EQ(0, r);
|
||||
r=nr_socket_getaddr(so2, &addr_so2);
|
||||
ASSERT_EQ(0, r);
|
||||
printf("Connect SO %s <-> %s\n", addr_so1.as_string, addr_so2.as_string);
|
||||
printf("Connecting SO %s <-> %s\n", addr_so1.as_string, addr_so2.as_string);
|
||||
r=nr_socket_connect(so1, &addr_so2);
|
||||
ASSERT_EQ(0, r);
|
||||
r=nr_socket_connect(so2, &addr_so1);
|
||||
@ -203,7 +203,8 @@ class MultiTcpSocketTest : public ::testing::Test {
|
||||
ASSERT_EQ(0, r);
|
||||
r=nr_socket_getaddr(from, &addr_from);
|
||||
ASSERT_EQ(0, r);
|
||||
printf("Send %s -> %s\n", addr_from.as_string, addr_to.as_string);
|
||||
printf("Sending %lu bytes %s -> %s\n", (unsigned long)len,
|
||||
addr_from.as_string, addr_to.as_string);
|
||||
r=nr_socket_sendto(from, data, len, 0, &addr_to);
|
||||
ASSERT_EQ(0, r);
|
||||
}
|
||||
@ -227,7 +228,8 @@ class MultiTcpSocketTest : public ::testing::Test {
|
||||
ASSERT_EQ(0, r);
|
||||
r=nr_socket_getaddr(expected_from, &addr_from);
|
||||
ASSERT_EQ(0, r);
|
||||
printf("Receive %s <- %s\n", addr_to.as_string, addr_from.as_string);
|
||||
printf("Receiving %lu bytes %s <- %s\n", (unsigned long)expected_len,
|
||||
addr_to.as_string, addr_from.as_string);
|
||||
r=nr_socket_recvfrom(sent_to, received_data, expected_len+1,
|
||||
&retlen, 0, &retaddr);
|
||||
ASSERT_EQ(0, r);
|
||||
@ -304,12 +306,15 @@ TEST_F(MultiTcpSocketTest, TestTwoSendsBeforeReceives) {
|
||||
SendData(socks[0], socks[1], data1, sizeof(data1));
|
||||
SendData(socks[0], socks[1], data2, sizeof(data2));
|
||||
RecvData(socks[0], socks[1], data1, sizeof(data1));
|
||||
/* ICE TCP framing turns TCP effectively into datagram mode */
|
||||
RecvData(socks[0], socks[1], data2, sizeof(data2));
|
||||
}
|
||||
|
||||
|
||||
TEST_F(MultiTcpSocketTest, TestTwoActiveBidirectionalTransmit) {
|
||||
const char data[] = "TestTwoActiveBidirectionalTransmit";
|
||||
TEST_F(MultiTcpSocketTest, TestTwoActiveBidirectionalTransmit) {
|
||||
const char data1[] = "TestTwoActiveBidirectionalTransmit";
|
||||
const char data2[] = "ReplyToTheFirstSocket";
|
||||
const char data3[] = "TestMessageFromTheSecondSocket";
|
||||
const char data4[] = "ThisIsAReplyToTheSecondSocket";
|
||||
socks[0] = Create(TCP_TYPE_PASSIVE);
|
||||
socks[1] = Create(TCP_TYPE_ACTIVE);
|
||||
socks[2] = Create(TCP_TYPE_ACTIVE);
|
||||
@ -317,14 +322,17 @@ TEST_F(MultiTcpSocketTest, TestTwoActiveBidirectionalTransmit) {
|
||||
Connect(socks[1], socks[0]);
|
||||
Connect(socks[2], socks[0]);
|
||||
|
||||
TransferData(socks[1], socks[0], data, sizeof(data));
|
||||
TransferData(socks[0], socks[1], data, sizeof(data));
|
||||
TransferData(socks[2], socks[0], data, sizeof(data));
|
||||
TransferData(socks[0], socks[2], data, sizeof(data));
|
||||
TransferData(socks[1], socks[0], data1, sizeof(data1));
|
||||
TransferData(socks[0], socks[1], data2, sizeof(data2));
|
||||
TransferData(socks[2], socks[0], data3, sizeof(data3));
|
||||
TransferData(socks[0], socks[2], data4, sizeof(data4));
|
||||
}
|
||||
|
||||
TEST_F(MultiTcpSocketTest, TestTwoPassiveBidirectionalTransmit) {
|
||||
const char data[] = "TestTwoPassiveBidirectionalTransmit";
|
||||
TEST_F(MultiTcpSocketTest, TestTwoPassiveBidirectionalTransmit) {
|
||||
const char data1[] = "TestTwoPassiveBidirectionalTransmit";
|
||||
const char data2[] = "FirstReply";
|
||||
const char data3[] = "TestTwoPassiveBidirectionalTransmitToTheSecondSock";
|
||||
const char data4[] = "SecondReply";
|
||||
socks[0] = Create(TCP_TYPE_PASSIVE);
|
||||
socks[1] = Create(TCP_TYPE_PASSIVE);
|
||||
socks[2] = Create(TCP_TYPE_ACTIVE);
|
||||
@ -333,13 +341,13 @@ TEST_F(MultiTcpSocketTest, TestTwoPassiveBidirectionalTransmit) {
|
||||
Connect(socks[2], socks[0]);
|
||||
Connect(socks[2], socks[1]);
|
||||
|
||||
TransferData(socks[2], socks[0], data, sizeof(data));
|
||||
TransferData(socks[0], socks[2], data, sizeof(data));
|
||||
TransferData(socks[2], socks[1], data, sizeof(data));
|
||||
TransferData(socks[1], socks[2], data, sizeof(data));
|
||||
TransferData(socks[2], socks[0], data1, sizeof(data1));
|
||||
TransferData(socks[0], socks[2], data2, sizeof(data2));
|
||||
TransferData(socks[2], socks[1], data3, sizeof(data3));
|
||||
TransferData(socks[1], socks[2], data4, sizeof(data4));
|
||||
}
|
||||
|
||||
TEST_F(MultiTcpSocketTest, TestActivePassiveWithStunServerMockup) {
|
||||
TEST_F(MultiTcpSocketTest, TestActivePassiveWithStunServerMockup) {
|
||||
/* Fake STUN message able to pass the nr_is_stun_msg check
|
||||
used in nr_socket_buffered_stun */
|
||||
const char stunMessage[] = {
|
||||
@ -371,7 +379,7 @@ TEST_F(MultiTcpSocketTest, TestConnectTwoSo) {
|
||||
|
||||
// test works on localhost only with delay applied:
|
||||
// tc qdisc add dev lo root netem delay 5ms
|
||||
TEST_F(MultiTcpSocketTest, DISABLED_TestTwoSoBidirectionalTransmit) {
|
||||
TEST_F(MultiTcpSocketTest, DISABLED_TestTwoSoBidirectionalTransmit) {
|
||||
const char data[] = "TestTwoSoBidirectionalTransmit";
|
||||
socks[0] = Create(TCP_TYPE_SO);
|
||||
socks[1] = Create(TCP_TYPE_SO);
|
||||
|
@ -162,12 +162,12 @@ int nr_ice_candidate_create(nr_ice_ctx *ctx,nr_ice_component *comp,nr_ice_socket
|
||||
break;
|
||||
|
||||
case SERVER_REFLEXIVE:
|
||||
if(r=nr_ice_candidate_format_stun_label(label, sizeof(label),cand))
|
||||
if(r=nr_ice_candidate_format_stun_label(label, sizeof(label), cand))
|
||||
ABORT(r);
|
||||
break;
|
||||
|
||||
case RELAYED:
|
||||
if(r=nr_ice_candidate_format_stun_label(label, sizeof(label),cand))
|
||||
if(r=nr_ice_candidate_format_stun_label(label, sizeof(label), cand))
|
||||
ABORT(r);
|
||||
break;
|
||||
|
||||
@ -181,11 +181,12 @@ int nr_ice_candidate_create(nr_ice_ctx *ctx,nr_ice_component *comp,nr_ice_socket
|
||||
}
|
||||
|
||||
if (tcp_type) {
|
||||
size_t slen=strlen(label)+1; /* plus space going to be added*/
|
||||
if (slen<sizeof(label)) {
|
||||
label[slen-1]=' ';
|
||||
strncpy(label+slen, nr_tcp_type_name(tcp_type), sizeof(label)-slen-1);
|
||||
label[sizeof(label)-1]=0;
|
||||
const char* ttype = nr_tcp_type_name(tcp_type);
|
||||
const int tlen = strlen(ttype)+1; /* plus space */
|
||||
const size_t llen=strlen(label);
|
||||
if (snprintf(label+llen, sizeof(label)-llen, " %s", ttype) != tlen) {
|
||||
r_log(LOG_ICE,LOG_ERR,"ICE(%s): truncated tcp type added to buffer",
|
||||
ctx->label);
|
||||
}
|
||||
}
|
||||
|
||||
@ -386,8 +387,7 @@ int nr_ice_candidate_compute_priority(nr_ice_candidate *cand)
|
||||
} else if(cand->base.protocol == IPPROTO_TCP) {
|
||||
if(r=NR_reg_get_uchar(NR_ICE_REG_PREF_TYPE_HOST_TCP,&type_preference))
|
||||
ABORT(r);
|
||||
} else
|
||||
ABORT(R_INTERNAL);
|
||||
}
|
||||
stun_priority=0;
|
||||
break;
|
||||
case RELAYED:
|
||||
@ -397,8 +397,7 @@ int nr_ice_candidate_compute_priority(nr_ice_candidate *cand)
|
||||
} else if(cand->base.protocol == IPPROTO_TCP) {
|
||||
if(r=NR_reg_get_uchar(NR_ICE_REG_PREF_TYPE_RELAYED_TCP,&type_preference))
|
||||
ABORT(r);
|
||||
} else
|
||||
ABORT(R_INTERNAL);
|
||||
}
|
||||
stun_priority=31-cand->stun_server->index;
|
||||
break;
|
||||
case SERVER_REFLEXIVE:
|
||||
@ -408,8 +407,7 @@ int nr_ice_candidate_compute_priority(nr_ice_candidate *cand)
|
||||
} else if(cand->base.protocol == IPPROTO_TCP) {
|
||||
if(r=NR_reg_get_uchar(NR_ICE_REG_PREF_TYPE_SRV_RFLX_TCP,&type_preference))
|
||||
ABORT(r);
|
||||
} else
|
||||
ABORT(R_INTERNAL);
|
||||
}
|
||||
stun_priority=31-cand->stun_server->index;
|
||||
break;
|
||||
case PEER_REFLEXIVE:
|
||||
@ -419,8 +417,7 @@ int nr_ice_candidate_compute_priority(nr_ice_candidate *cand)
|
||||
} else if(cand->base.protocol == IPPROTO_TCP) {
|
||||
if(r=NR_reg_get_uchar(NR_ICE_REG_PREF_TYPE_PEER_RFLX_TCP,&type_preference))
|
||||
ABORT(r);
|
||||
} else
|
||||
ABORT(R_INTERNAL);
|
||||
}
|
||||
stun_priority=0;
|
||||
break;
|
||||
default:
|
||||
@ -947,7 +944,9 @@ int nr_ice_format_candidate_attribute(nr_ice_candidate *cand, char *attr, int ma
|
||||
}
|
||||
|
||||
if (cand->base.protocol==IPPROTO_TCP && cand->tcp_type){
|
||||
len=strlen(attr); attr+=len; maxlen-=len;
|
||||
len=strlen(attr);
|
||||
attr+=len;
|
||||
maxlen-=len;
|
||||
snprintf(attr,maxlen," tcptype %s",nr_tcp_type_name(cand->tcp_type));
|
||||
}
|
||||
|
||||
|
@ -414,8 +414,7 @@ static int nr_ice_component_initialize_tcp(struct nr_ice_ctx_ *ctx,nr_ice_compon
|
||||
if(r!=R_NOT_FOUND)
|
||||
ABORT(r);
|
||||
}
|
||||
else{
|
||||
if(suppress)
|
||||
else if(suppress) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -282,9 +282,9 @@ int nr_ice_socket_close(nr_ice_socket *isock)
|
||||
if (!isock||!isock->sock)
|
||||
return(0);
|
||||
|
||||
assert(isock->sock!=0);
|
||||
if (isock->type != NR_ICE_SOCKET_TYPE_STREAM_TCP){
|
||||
nr_socket_getfd(isock->sock,&fd);
|
||||
assert(isock->sock!=0);
|
||||
if(fd != no_socket){
|
||||
NR_ASYNC_CANCEL(fd,NR_ASYNC_WAIT_READ);
|
||||
NR_ASYNC_CANCEL(fd,NR_ASYNC_WAIT_WRITE);
|
||||
|
@ -56,16 +56,22 @@ static void nr_tcp_socket_readable_cb(NR_SOCKET s, int how, void *arg);
|
||||
|
||||
static int nr_tcp_socket_ctx_destroy(nr_tcp_socket_ctx **objp)
|
||||
{
|
||||
nr_tcp_socket_ctx *sock;
|
||||
|
||||
if (!objp || !*objp)
|
||||
return(0);
|
||||
|
||||
nr_socket_destroy(&(*objp)->inner);
|
||||
RFREE(*objp);
|
||||
*objp=NULL;
|
||||
sock=*objp;
|
||||
*objp=0;
|
||||
|
||||
nr_socket_destroy(&sock->inner);
|
||||
|
||||
RFREE(sock);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* This takes ownership of nrsock whether it fails or not. */
|
||||
static int nr_tcp_socket_ctx_create(nr_socket *nrsock, int is_framed,
|
||||
int max_pending, nr_tcp_socket_ctx **sockp)
|
||||
{
|
||||
@ -409,8 +415,8 @@ static int nr_socket_multi_tcp_destroy(void **objp)
|
||||
if (!objp || !*objp)
|
||||
return 0;
|
||||
|
||||
sock = (nr_socket_multi_tcp *)*objp;
|
||||
*objp = 0;
|
||||
sock=(nr_socket_multi_tcp *)*objp;
|
||||
*objp=0;
|
||||
|
||||
/* Cancel waiting on the socket */
|
||||
if (sock->listen_socket && !nr_socket_getfd(sock->listen_socket, &fd)) {
|
||||
@ -436,14 +442,15 @@ static int nr_socket_multi_tcp_destroy(void **objp)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int nr_socket_multi_tcp_sendto(void *obj,const void *msg, size_t len,
|
||||
static int nr_socket_multi_tcp_sendto(void *obj, const void *msg, size_t len,
|
||||
int flags, nr_transport_addr *to)
|
||||
{
|
||||
int r, _status;
|
||||
nr_socket_multi_tcp *sock = (nr_socket_multi_tcp *)obj;
|
||||
nr_socket_multi_tcp *sock=(nr_socket_multi_tcp *)obj;
|
||||
nr_socket *nrsock;
|
||||
|
||||
if ((r=nr_socket_multi_tcp_get_sock_connected_to(sock, to, PREALLOC_DONT_CONNECT_UNLESS_SO, &nrsock)))
|
||||
if ((r=nr_socket_multi_tcp_get_sock_connected_to(sock, to,
|
||||
PREALLOC_DONT_CONNECT_UNLESS_SO, &nrsock)))
|
||||
ABORT(r);
|
||||
|
||||
if((r=nr_socket_sendto(nrsock, msg, len, flags, to)))
|
||||
@ -460,10 +467,13 @@ static int nr_socket_multi_tcp_sendto(void *obj,const void *msg, size_t len,
|
||||
static int nr_socket_multi_tcp_recvfrom(void *obj,void * restrict buf,
|
||||
size_t maxlen, size_t *len, int flags, nr_transport_addr *from)
|
||||
{
|
||||
int r, _status;
|
||||
nr_socket_multi_tcp *sock = (nr_socket_multi_tcp *)obj;
|
||||
int r, _status = 0;
|
||||
nr_socket_multi_tcp *sock=(nr_socket_multi_tcp *)obj;
|
||||
nr_tcp_socket_ctx *tcpsock;
|
||||
|
||||
if (TAILQ_EMPTY(&sock->sockets))
|
||||
ABORT(R_FAILED);
|
||||
|
||||
TAILQ_FOREACH(tcpsock, &sock->sockets, entry) {
|
||||
if (nr_transport_addr_is_wildcard(&tcpsock->remote_addr))
|
||||
continue;
|
||||
@ -481,11 +491,12 @@ static int nr_socket_multi_tcp_recvfrom(void *obj,void * restrict buf,
|
||||
|
||||
TAILQ_REMOVE(&sock->sockets, tcpsock, entry);
|
||||
nr_tcp_socket_ctx_destroy(&tcpsock);
|
||||
r_log(LOG_ICE,LOG_DEBUG,"%s:%d function %s(from:%s) failed with error %d",__FILE__,__LINE__,__FUNCTION__,from->as_string,_status);
|
||||
r_log(LOG_ICE,LOG_DEBUG,"%s:%d function %s(from:%s) failed with error %d",__FILE__,__LINE__,__FUNCTION__,from->as_string,r);
|
||||
ABORT(r);
|
||||
}
|
||||
}
|
||||
|
||||
/* this also gets returned if all tcpsocks have wildcard remote_addr */
|
||||
_status=R_WOULDBLOCK;
|
||||
abort:
|
||||
|
||||
@ -494,14 +505,14 @@ static int nr_socket_multi_tcp_recvfrom(void *obj,void * restrict buf,
|
||||
|
||||
static int nr_socket_multi_tcp_getaddr(void *obj, nr_transport_addr *addrp)
|
||||
{
|
||||
nr_socket_multi_tcp *sock = (nr_socket_multi_tcp *)obj;
|
||||
nr_socket_multi_tcp *sock=(nr_socket_multi_tcp *)obj;
|
||||
|
||||
return nr_transport_addr_copy(addrp,&sock->addr);
|
||||
}
|
||||
|
||||
static int nr_socket_multi_tcp_close(void *obj)
|
||||
{
|
||||
nr_socket_multi_tcp *sock = (nr_socket_multi_tcp *)obj;
|
||||
nr_socket_multi_tcp *sock=(nr_socket_multi_tcp *)obj;
|
||||
nr_tcp_socket_ctx *tcpsock;
|
||||
|
||||
if(sock->listen_socket)
|
||||
@ -516,18 +527,19 @@ static int nr_socket_multi_tcp_close(void *obj)
|
||||
|
||||
static void nr_tcp_socket_readable_cb(NR_SOCKET s, int how, void *arg)
|
||||
{
|
||||
nr_socket_multi_tcp *sock = (nr_socket_multi_tcp *)arg;
|
||||
nr_socket_multi_tcp *sock=(nr_socket_multi_tcp *)arg;
|
||||
|
||||
// rearm
|
||||
NR_ASYNC_WAIT(s, NR_ASYNC_WAIT_READ, nr_tcp_socket_readable_cb, arg);
|
||||
|
||||
if (sock->readable_cb)
|
||||
sock->readable_cb(s, how, sock->readable_cb_arg);
|
||||
|
||||
NR_ASYNC_WAIT(s, NR_ASYNC_WAIT_READ, nr_tcp_socket_readable_cb, arg);
|
||||
}
|
||||
|
||||
static int nr_socket_multi_tcp_connect(void *obj, nr_transport_addr *addr)
|
||||
{
|
||||
int r, _status;
|
||||
nr_socket_multi_tcp *sock = (nr_socket_multi_tcp *)obj;
|
||||
nr_socket_multi_tcp *sock=(nr_socket_multi_tcp *)obj;
|
||||
nr_socket *nrsock;
|
||||
|
||||
if ((r=nr_socket_multi_tcp_get_sock_connected_to(sock,addr,PREALLOC_CONNECT_FRAMED,&nrsock)))
|
||||
@ -543,16 +555,16 @@ abort:
|
||||
|
||||
static void nr_tcp_multi_lsocket_readable_cb(NR_SOCKET s, int how, void *arg)
|
||||
{
|
||||
nr_socket_multi_tcp *sock = (nr_socket_multi_tcp *)arg;
|
||||
nr_socket_multi_tcp *sock=(nr_socket_multi_tcp *)arg;
|
||||
nr_socket *newsock;
|
||||
nr_transport_addr remote_addr;
|
||||
nr_tcp_socket_ctx *tcp_sock_ctx;
|
||||
int r;
|
||||
|
||||
//rearm
|
||||
NR_ASYNC_WAIT(s, NR_ASYNC_WAIT_READ, nr_tcp_multi_lsocket_readable_cb, sock);
|
||||
// rearm
|
||||
NR_ASYNC_WAIT(s, NR_ASYNC_WAIT_READ, nr_tcp_multi_lsocket_readable_cb, arg);
|
||||
|
||||
/* accept and add to socket_list */
|
||||
/* accept */
|
||||
if (nr_socket_accept(sock->listen_socket, &remote_addr, &newsock))
|
||||
return;
|
||||
|
||||
@ -573,7 +585,7 @@ static void nr_tcp_multi_lsocket_readable_cb(NR_SOCKET s, int how, void *arg)
|
||||
static int nr_socket_multi_tcp_listen(void *obj, int backlog)
|
||||
{
|
||||
int r, _status;
|
||||
nr_socket_multi_tcp *sock = (nr_socket_multi_tcp *)obj;
|
||||
nr_socket_multi_tcp *sock=(nr_socket_multi_tcp *)obj;
|
||||
NR_SOCKET fd;
|
||||
|
||||
if(!sock->listen_socket)
|
||||
|
@ -224,7 +224,9 @@ static int nr_socket_buffered_stun_sendto(void *obj,const void *msg, size_t len,
|
||||
if (len > NR_MAX_FRAME_SIZE)
|
||||
ABORT(R_FAILED);
|
||||
|
||||
frame = RMALLOC(len + sizeof(nr_frame_header));
|
||||
if (!(frame = RMALLOC(len + sizeof(nr_frame_header))))
|
||||
ABORT(R_NO_MEMORY);
|
||||
|
||||
frame->frame_length = htons(len);
|
||||
memcpy(frame->data, msg, len);
|
||||
len += sizeof(nr_frame_header);
|
||||
@ -280,11 +282,13 @@ reread:
|
||||
|
||||
/* No more bytes expected */
|
||||
if (sock->read_state == NR_ICE_SOCKET_READ_NONE) {
|
||||
size_t remaining_length;
|
||||
if (sock->framing_type == ICE_TCP_FRAMING) {
|
||||
sock->bytes_needed = ntohs(frame->frame_length);
|
||||
if (sock->bytes_read < sizeof(nr_frame_header))
|
||||
ABORT(R_BAD_DATA);
|
||||
remaining_length = ntohs(frame->frame_length);
|
||||
} else {
|
||||
int tmp_length;
|
||||
size_t remaining_length;
|
||||
|
||||
/* Parse the header */
|
||||
if (r = nr_stun_message_length(sock->buffer, sock->bytes_read, &tmp_length))
|
||||
@ -294,18 +298,21 @@ reread:
|
||||
ABORT(R_BAD_DATA);
|
||||
remaining_length = tmp_length;
|
||||
|
||||
/* Check to see if we have enough room */
|
||||
if ((sock->buffer_size - sock->bytes_read) < remaining_length)
|
||||
ABORT(R_BAD_DATA);
|
||||
|
||||
/* Set ourselves up to read the rest of the data */
|
||||
sock->bytes_needed = remaining_length;
|
||||
}
|
||||
/* Check to see if we have enough room */
|
||||
if ((sock->buffer_size - sock->bytes_read) < remaining_length)
|
||||
ABORT(R_BAD_DATA);
|
||||
|
||||
/* Set ourselves up to read the rest of the data */
|
||||
sock->bytes_needed = remaining_length;
|
||||
|
||||
sock->read_state = NR_ICE_SOCKET_READ_HDR;
|
||||
goto reread;
|
||||
}
|
||||
|
||||
assert(skip_hdr_size <= sock->bytes_read);
|
||||
if (skip_hdr_size > sock->bytes_read)
|
||||
ABORT(R_BAD_DATA);
|
||||
sock->bytes_read -= skip_hdr_size;
|
||||
|
||||
if (maxlen < sock->bytes_read)
|
||||
|
Loading…
Reference in New Issue
Block a user