Chromium Code Reviews| Index: talk/media/sctp/sctpdataengine.cc |
| diff --git a/talk/media/sctp/sctpdataengine.cc b/talk/media/sctp/sctpdataengine.cc |
| index 8c8a6a192fa25833c3de66c0587b9ed7ed3bccb3..2cbaf6233d65ea89357424ce465a2b99ee81b6de 100644 |
| --- a/talk/media/sctp/sctpdataengine.cc |
| +++ b/talk/media/sctp/sctpdataengine.cc |
| @@ -109,6 +109,8 @@ typedef rtc::ScopedMessageData<rtc::Buffer> OutboundPacketMessage; |
| // take off 80 bytes for DTLS/TURN/TCP/IP overhead. |
| static const size_t kSctpMtu = 1200; |
| +// The size of the SCTP association send buffer. |
| +static const int kSendBufferSize = 262144; |
|
pthatcher1
2015/08/18 21:51:52
Can you comment on how this number was chosen?
lally1
2015/08/24 15:46:39
Done.
|
| enum { |
| MSG_SCTPINBOUNDPACKET = 1, // MessageData is SctpInboundPacket |
| MSG_SCTPOUTBOUNDPACKET = 2, // MessageData is rtc:Buffer |
| @@ -177,11 +179,11 @@ static bool GetDataMediaType( |
| } |
| // Log the packet in text2pcap format, if log level is at LS_VERBOSE. |
| -static void VerboseLogPacket(void *addr, size_t length, int direction) { |
| +static void VerboseLogPacket(void *data, size_t length, int direction) { |
| if (LOG_CHECK_LEVEL(LS_VERBOSE) && length > 0) { |
| char *dump_buf; |
| if ((dump_buf = usrsctp_dumppacket( |
| - addr, length, direction)) != NULL) { |
| + data, length, direction)) != NULL) { |
| LOG(LS_VERBOSE) << dump_buf; |
| usrsctp_freedumpbuffer(dump_buf); |
| } |
| @@ -258,6 +260,11 @@ SctpDataEngine::SctpDataEngine() { |
| // TODO(ldixon): Consider turning this on/off. |
| usrsctp_sysctl_set_sctp_ecn_enable(0); |
| + int send_size = usrsctp_sysctl_get_sctp_sendspace(); |
| + if (send_size != kSendBufferSize) { |
| + LOG(LS_ERROR) << "Got different send size than expected: " << send_size; |
| + } |
| + |
| // TODO(ldixon): Consider turning this on/off. |
| // This is not needed right now (we don't do dynamic address changes): |
| // If SCTP Auto-ASCONF is enabled, the peer is informed automatically |
| @@ -315,6 +322,9 @@ DataMediaChannel* SctpDataEngine::CreateChannel( |
| return new SctpDataMediaChannel(rtc::Thread::Current()); |
| } |
| +// Our registrar of sockets to their channels. Used for callbacks. |
| +std::vector<SctpDataMediaChannel*> SctpDataMediaChannel::sock_channel_map_; |
|
pthatcher1
2015/08/18 21:51:52
Since it's not a map anymore, perhaps channels_ wo
lally1
2015/08/24 15:46:39
Done.
|
| + |
| SctpDataMediaChannel::SctpDataMediaChannel(rtc::Thread* thread) |
| : worker_thread_(thread), |
| local_port_(kSctpDefaultPort), |
| @@ -323,10 +333,19 @@ SctpDataMediaChannel::SctpDataMediaChannel(rtc::Thread* thread) |
| sending_(false), |
| receiving_(false), |
| debug_name_("SctpDataMediaChannel") { |
| + sock_channel_map_.push_back(this); |
| } |
| SctpDataMediaChannel::~SctpDataMediaChannel() { |
| CloseSctpSocket(); |
| + auto it = std::find(sock_channel_map_.begin(), |
| + sock_channel_map_.end(), |
| + this); |
| + if (it != sock_channel_map_.end()) { |
| + sock_channel_map_.erase(it); |
| + } else { |
| + LOG(LS_ERROR) << "~SctpDataMediaChannel: the channel wasn't registered."; |
| + } |
|
pthatcher1
2015/08/18 21:51:53
An early return might look a little better:
if (i
lally1
2015/08/24 15:46:39
Done, in OnChannelDestroyed(), where this code was
|
| } |
| sockaddr_conn SctpDataMediaChannel::GetSctpSockAddr(int port) { |
| @@ -341,14 +360,36 @@ sockaddr_conn SctpDataMediaChannel::GetSctpSockAddr(int port) { |
| return sconn; |
| } |
| +// static |
| +int SctpDataMediaChannel::SendThresholdCallback(struct socket* sock, |
| + uint32_t sb_free) { |
| + for (auto p:sock_channel_map_) { |
| + if (p->socket() == sock) { |
|
pthatcher1
2015/08/18 21:51:52
Did you mean to put this in GetSctpChannel?
lally1
2015/08/24 15:46:39
I took that method out. Did you want it back in?
|
| + p->SignalReadyToSend(true); |
| + return 0; |
| + } |
| + } |
| + LOG(LS_ERROR) << "SendThresholdCallback: Failed to get channel for socket " |
| + << sock; |
| + return 0; |
| +} |
| + |
| bool SctpDataMediaChannel::OpenSctpSocket() { |
| if (sock_) { |
| LOG(LS_VERBOSE) << debug_name_ |
| << "->Ignoring attempt to re-create existing socket."; |
| return false; |
| } |
| + |
| + // kSendBufferSize is our expected default buffer size. If it isn't |
| + // reflective of reality we'll log an error, but we still have to do |
| + // something reasonable here. |
|
pthatcher1
2015/08/18 21:51:52
This comment looks like it belongs up by where kSe
lally1
2015/08/24 15:46:39
No I just wrote it poorly. Rewritten.
|
| + const int send_threshold = usrsctp_sysctl_get_sctp_sendspace() / 2; |
| + |
| sock_ = usrsctp_socket(AF_CONN, SOCK_STREAM, IPPROTO_SCTP, |
| - cricket::OnSctpInboundPacket, NULL, 0, this); |
| + cricket::OnSctpInboundPacket, |
| + &SctpDataMediaChannel::SendThresholdCallback, |
| + send_threshold, this); |
| if (!sock_) { |
| LOG_ERRNO(LS_ERROR) << debug_name_ << "Failed to create SCTP socket."; |
| return false; |
| @@ -393,7 +434,8 @@ bool SctpDataMediaChannel::OpenSctpSocket() { |
| } |
| // Disable MTU discovery |
| - struct sctp_paddrparams params = {{0}}; |
| + struct sctp_paddrparams params; |
| + memset(¶ms, 0, sizeof(params)); |
| params.spp_assoc_id = 0; |
| params.spp_flags = SPP_PMTUD_DISABLE; |
| params.spp_pathmtu = kSctpMtu; |
| @@ -904,10 +946,17 @@ bool SctpDataMediaChannel::SetRecvCodecs(const std::vector<DataCodec>& codecs) { |
| void SctpDataMediaChannel::OnPacketFromSctpToNetwork( |
| rtc::Buffer* buffer) { |
| - if (buffer->size() > kSctpMtu) { |
| + // usrsctp seems to interpret the MTU we give it strangely -- it seems to |
| + // give us back packets bigger than that MTU, if only by a fixed amount. |
| + // This is that amount that we've observed. |
| + const int kSctpOverhead = 76; |
| + if (buffer->size() > (kSctpOverhead + kSctpMtu)) { |
| LOG(LS_ERROR) << debug_name_ << "->OnPacketFromSctpToNetwork(...): " |
| << "SCTP seems to have made a packet that is bigger " |
| - "than its official MTU."; |
| + << "than its official MTU: " << buffer->size() |
| + << " vs max of " << kSctpMtu |
| + << " even after adding " << kSctpOverhead |
| + << " extra SCTP overhead"; |
| } |
| MediaChannel::SendPacket(buffer); |
| } |