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

[core] Fixed socket options that are not allowed to be set on a group. #3089

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions docs/API/API-socket-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,10 @@ The following table lists SRT API socket options in alphabetical order. Option d

| Option Name | Since | Restrict | Type | Units | Default | Range | Dir |Entity |
| :------------------------------------------------------ | :---: | :------: | :-------: | :-----: | :---------------: | :------: |:---:|:-----:|
| [`SRTO_BINDTODEVICE`](#SRTO_BINDTODEVICE) | 1.4.2 | pre-bind | `string` | | | | RW | GSD+ |
| [`SRTO_BINDTODEVICE`](#SRTO_BINDTODEVICE) | 1.4.2 | pre-bind | `string` | | | | RW | S |
| [`SRTO_CONGESTION`](#SRTO_CONGESTION) | 1.3.0 | pre | `string` | | "live" | \* | W | S |
| [`SRTO_CONNTIMEO`](#SRTO_CONNTIMEO) | 1.1.2 | pre | `int32_t` | ms | 3000 | 0.. | W | GSD+ |
| [`SRTO_CRYPTOMODE`](#SRTO_CRYPTOMODE) | 1.5.2 | pre | `int32_t` | | 0 (Auto) | [0, 2] | W | GSD |
| [`SRTO_CRYPTOMODE`](#SRTO_CRYPTOMODE) | 1.5.2 | pre | `int32_t` | | 0 (Auto) | [0, 2] | W | GSD |
| [`SRTO_DRIFTTRACER`](#SRTO_DRIFTTRACER) | 1.4.2 | post | `bool` | | true | | RW | GSD |
| [`SRTO_ENFORCEDENCRYPTION`](#SRTO_ENFORCEDENCRYPTION) | 1.3.2 | pre | `bool` | | true | | W | GSD |
| [`SRTO_EVENT`](#SRTO_EVENT) | | | `int32_t` | flags | | | R | S |
Expand Down Expand Up @@ -269,7 +269,7 @@ The following table lists SRT API socket options in alphabetical order. Option d

| OptName | Since | Restrict | Type | Units | Default | Range | Dir |Entity|
| --------------------- | ----- | -------- | -------- | ------ | -------- | ------ |-----|------|
| `SRTO_BINDTODEVICE` | 1.4.2 | pre-bind | `string` | | | | RW | GSD+ |
| `SRTO_BINDTODEVICE` | 1.4.2 | pre-bind | `string` | | | | RW | S |

Refers to the `SO_BINDTODEVICE` system socket option for `SOL_SOCKET` level.
This effectively limits the packets received by this socket to only those
Expand Down
29 changes: 27 additions & 2 deletions srtcore/group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,31 @@ void CUDTGroup::setOpt(SRT_SOCKOPT optName, const void* optval, int optlen)

switch (optName)
{
// First go options that are NOT ALLOWED to be modified on the group.
// (socket-only), or are read-only.

case SRTO_ISN: // read-only
case SRTO_STATE: // read-only
case SRTO_EVENT: // read-only
case SRTO_SNDDATA: // read-only
case SRTO_RCVDATA: // read-only
case SRTO_KMSTATE: // read-only
case SRTO_VERSION: // read-only
case SRTO_PEERVERSION: // read-only
case SRTO_SNDKMSTATE:
case SRTO_RCVKMSTATE:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are also read-only.

case SRTO_GROUPTYPE: // read-only
LOGC(gmlog.Error, log << "group option setter: this option ("<< int(optName) << ") is read-only");
throw CUDTException(MJ_NOTSUP, MN_INVAL, 0);

case SRTO_SENDER: // deprecated (1.2.0 version legacy)
case SRTO_IPV6ONLY: // link-type specific
case SRTO_RENDEZVOUS: // socket-only
case SRTO_BINDTODEVICE: // socket-specific
case SRTO_GROUPCONNECT: // listener-specific
LOGC(gmlog.Error, log << "group option setter: this option ("<< int(optName) << ") is socket- or link-specific");
throw CUDTException(MJ_NOTSUP, MN_INVAL, 0);

case SRTO_RCVSYN:
m_bSynRecving = cast_optval<bool>(optval, optlen);
return;
Expand All @@ -369,7 +394,7 @@ void CUDTGroup::setOpt(SRT_SOCKOPT optName, const void* optval, int optlen)
const int min_timeo_ms = (int) CSrtConfig::COMM_DEF_MIN_STABILITY_TIMEOUT_MS;
if (val_ms < min_timeo_ms)
{
LOGC(qmlog.Error,
LOGC(gmlog.Error,
log << "group option: SRTO_GROUPMINSTABLETIMEO min allowed value is " << min_timeo_ms << " ms.");
throw CUDTException(MJ_NOTSUP, MN_INVAL, 0);
}
Expand All @@ -385,7 +410,7 @@ void CUDTGroup::setOpt(SRT_SOCKOPT optName, const void* optval, int optlen)

if (val_ms > idletmo)
{
LOGC(qmlog.Error,
LOGC(gmlog.Error,
log << "group option: SRTO_GROUPMINSTABLETIMEO=" << val_ms << " exceeds SRTO_PEERIDLETIMEO=" << idletmo);
throw CUDTException(MJ_NOTSUP, MN_INVAL, 0);
}
Expand Down
2 changes: 1 addition & 1 deletion srtcore/srt.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ typedef enum SRT_SOCKOPT {
SRTO_RCVTIMEO = 14, // recv() timeout
SRTO_REUSEADDR = 15, // reuse an existing port or create a new one
SRTO_MAXBW = 16, // maximum bandwidth (bytes per second) that the connection can use
SRTO_STATE = 17, // current socket state, see UDTSTATUS, read only
SRTO_STATE = 17, // current socket state, see SRT_SOCKSTATUS, read only
SRTO_EVENT = 18, // current available events associated with the socket
SRTO_SNDDATA = 19, // size of data in the sending buffer
SRTO_RCVDATA = 20, // size of data available for recv
Expand Down
10 changes: 5 additions & 5 deletions test/test_bonding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ TEST(Bonding, Options)
TestInit srtinit;

// Create a group
const SRTSOCKET grp = srt_create_group(SRT_GTYPE_BROADCAST);
MAKE_UNIQUE_SOCK(grp, "broadcast group", srt_create_group(SRT_GTYPE_BROADCAST));

// rendezvous shall not be allowed to be set on the group
// XXX actually it is possible, but no one tested it. POSTPONE.
Expand Down Expand Up @@ -431,9 +431,10 @@ TEST(Bonding, Options)
// First wait - until it's let go with accepting
latch.wait(ux);

sockaddr_any revsa;
SRTSOCKET gs = srt_accept(lsn, revsa.get(), &revsa.len);
ASSERT_NE(gs, SRT_ERROR);
//sockaddr_any revsa;
SRTSOCKET lsna [1] = { lsn };
SRTSOCKET gs = srt_accept_bond(lsna, 1, 1000);
ASSERT_NE(gs, SRT_INVALID_SOCK);

check_streamid(gs);

Expand Down Expand Up @@ -530,7 +531,6 @@ TEST(Bonding, Options)
}

accept_and_close.join();
srt_close(grp);
}

inline SRT_SOCKGROUPCONFIG PrepareEndpoint(const std::string& host, int port)
Expand Down
Loading