Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into belabox
Browse files Browse the repository at this point in the history
  • Loading branch information
datagutt committed Nov 7, 2024
2 parents df72adf + a8c6b65 commit 1852d48
Show file tree
Hide file tree
Showing 12 changed files with 166 additions and 74 deletions.
15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1046,8 +1046,23 @@ macro(srt_set_stdcxx targetname spec)
endif()
endmacro()

macro(srt_set_stdc targetname spec)
set (stdcspec ${spec})
if (NOT "${stdcspec}" STREQUAL "")
if (CMAKE_VERSION VERSION_LESS "3.1")
target_compile_options(${targetname} PRIVATE -std=c${stdcspec})
message(STATUS "C STD: ${targetname}: forced C${stdcspec} standard - GNU option: -std=c${stdcspec}")
else()
set_target_properties(${targetname} PROPERTIES C_STANDARD ${stdcspec})
message(STATUS "C STD: ${targetname}: forced C${stdcspec} standard - portable way")
endif()
else()
message(STATUS "APP: ${targetname}: using default C standard")
endif()
endmacro()

srt_set_stdcxx(srt_virtual "${USE_CXX_STD_LIB}")
srt_set_stdc(srt_virtual "99")

set (VIRTUAL_srt $<TARGET_OBJECTS:srt_virtual>)

Expand Down
2 changes: 1 addition & 1 deletion apps/verbose.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#define INC_SRT_VERBOSE_HPP

#include <iostream>
#include "atomic.h"
#include "sync.h"

namespace Verbose
{
Expand Down
6 changes: 6 additions & 0 deletions docs/API/API-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,9 @@ automatically created to handle the incoming connection on the listening socket
(and is about to be returned by [`srt_accept`](#srt_accept)), but before the
connection has been accepted.

Note the callback must be set before starting listening,
i.e. before `srt_listen` is called.

**Arguments**:

* `lsn`: Listening socket where you want to install the callback hook
Expand Down Expand Up @@ -1020,6 +1023,9 @@ mode ([`SRTO_RCVSYN`](API-socket-options.md#SRTO_RCVSYN) option set to true).
It is guaranteed to be called when a socket is in non-blocking mode, or when you
use a group.

Note the callback must be set before starting the connection procedure,
i.e. before `srt_connect`, `srt_connect_bind`, etc. is called.

This function is mainly intended to be used with group connections. Note that even
if you use a group connection in blocking mode, after the group is considered
connected the member connections still continue in background. Also, when some
Expand Down
1 change: 1 addition & 0 deletions docs/build/build-macOS.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Install [CMake](https://cmake.org/) and OpenSSL with development files from `bre
```shell
brew install cmake
brew install openssl
brew install pkgconfig
```

SRT can be now built with `cmake` or `make` on Mac.
Expand Down
2 changes: 1 addition & 1 deletion scripts/release-notes/generate_release_notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def define_area(msg):
if msg.startswith(f'[{area}] '):
return area

return np.NaN
return np.nan


def delete_prefix(msg):
Expand Down
59 changes: 51 additions & 8 deletions scripts/win-installer/build-win-installer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,53 @@ Write-Output "Windows version info: $VersionInfo"
#-----------------------------------------------------------------------------

# Locate OpenSSL root from local installation.
$SslRoot = @{
"x64" = "C:\Program Files\OpenSSL-Win64";
"Win32" = "C:\Program Files (x86)\OpenSSL-Win32"
# After version 3.something, OpenSSL has changed its installation layout.
# We have to look for OpenSSL libraries in various locations.
$SSL = @{
"x64" = @{
"alt" = "Win64";
"bits" = 64;
"root" = "C:\Program Files\OpenSSL-Win64"
};
"Win32" = @{
"alt" = "x86";
"bits" = 32;
"root" = "C:\Program Files (x86)\OpenSSL-Win32"
}
}

# Verify OpenSSL directories.
# Verify OpenSSL directories and static libraries.
Write-Output "Searching OpenSSL libraries ..."
$Missing = 0
foreach ($file in @($SslRoot["x64"], $SslRoot["Win32"])) {
if (-not (Test-Path $file)) {
Write-Output "**** Missing $file"
foreach ($arch in @("x64", "Win32")) {
$root = $SSL[$arch]["root"]
$bits = $SSL[$arch]["bits"]
$alt = $SSL[$arch]["alt"]
if (-not (Test-Path $root)) {
Write-Output "**** Missing $root"
$Missing = $Missing + 1
}
else {
foreach ($lib in @("ssl", "crypto")) {
foreach ($conf in @("MD", "MDd")) {
$name = "lib${lib}${conf}"
$SSL[$arch][$name] = ""
foreach ($try in @("$root\lib\VC\static\lib${lib}${bits}${conf}.lib",
"$root\lib\VC\${arch}\${conf}\lib${lib}_static.lib",
"$root\lib\VC\${alt}\${conf}\lib${lib}_static.lib")) {
if (Test-Path $try) {
$SSL[$arch][$name] = $try
New-Variable "lib${lib}${bits}${conf}" "$try"
break
}
}
if (-not $SSL[$arch][$name]) {
Write-Output "**** OpenSSL static library for $name not found"
$Missing = $Missing + 1
}
}
}
}
}
if ($Missing -gt 0) {
Exit-Script "Missing $Missing OpenSSL files, use install-openssl.ps1 to install OpenSSL"
Expand Down Expand Up @@ -157,7 +192,7 @@ foreach ($Platform in @("x64", "Win32")) {

# Run CMake.
Write-Output "Configuring build for platform $Platform ..."
$SRoot = $SslRoot[$Platform]
$SRoot = $SSL[$Platform]["root"]
& $CMake -S $RepoDir -B $BuildDir -A $Platform `
-DENABLE_STDCXX_SYNC=ON `
-DOPENSSL_ROOT_DIR="$SRoot" `
Expand Down Expand Up @@ -210,6 +245,14 @@ Write-Output "Building installer ..."
/DOutDir="$OutDir" `
/DBuildRoot="$TmpDir" `
/DRepoDir="$RepoDir" `
/Dlibssl32MD="$libssl32MD" `
/Dlibssl32MDd="$libssl32MDd" `
/Dlibcrypto32MD="$libcrypto32MD" `
/Dlibcrypto32MDd="$libcrypto32MDd" `
/Dlibssl64MD="$libssl64MD" `
/Dlibssl64MDd="$libssl64MDd" `
/Dlibcrypto64MD="$libcrypto64MD" `
/Dlibcrypto64MDd="$libcrypto64MDd" `
"$ScriptDir\libsrt.nsi"

if (-not (Test-Path $InstallExe)) {
Expand Down
61 changes: 41 additions & 20 deletions scripts/win-installer/install-openssl.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#-----------------------------------------------------------------------------
#
# SRT - Secure, Reliable, Transport
# Copyright (c) 2021, Thierry Lelegard
# Copyright (c) 2021-2024, Thierry Lelegard
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down Expand Up @@ -36,7 +36,26 @@ param(
)

Write-Output "OpenSSL download and installation procedure"
$OpenSSLHomePage = "http://slproweb.com/products/Win32OpenSSL.html"

# A bit of history: Where to load OpenSSL binaries from?
#
# The packages are built by "slproweb". The binaries are downloadable from
# their Web page at: http://slproweb.com/products/Win32OpenSSL.html
#
# Initially, the HTML for this page was built on server-side. This script
# grabbed the URL content, parse the HTML and extracted the URL of the
# binaries for the latest OpenSSL packages from the "href" of the links.
#
# At some point in 2024, the site changed policy. The Web page is no longer
# built on server-side, but on client-side. The downloaded HTML contains some
# JavaScript which dynamically builds the URL of the binaries for the latest
# OpenSSL binaries. The previous method now finds no valid package URL from
# the downloaded page (a full browser is needed to execute the JavaScript).
# The JavaScript downloads a JSON file which contains all references to
# the OpenSSL binaries. This script now uses the same method: download that
# JSON file and parse it.

$PackageList = "https://github.com/slproweb/opensslhashes/raw/master/win32_openssl_hashes.json"

# A function to exit this script.
function Exit-Script([string]$Message = "")
Expand All @@ -62,11 +81,11 @@ $TmpDir = "$RootDir\tmp"
# Without this, Invoke-WebRequest is awfully slow.
$ProgressPreference = 'SilentlyContinue'

# Get the HTML page for OpenSSL downloads.
# Get the JSON configuration file for OpenSSL downloads.
$status = 0
$message = ""
try {
$response = Invoke-WebRequest -UseBasicParsing -UserAgent Download -Uri $OpenSSLHomePage
$response = Invoke-WebRequest -UseBasicParsing -UserAgent Download -Uri $PackageList
$status = [int] [Math]::Floor($response.StatusCode / 100)
}
catch {
Expand All @@ -77,22 +96,27 @@ if ($status -ne 1 -and $status -ne 2) {
Exit-Script "Status code $($response.StatusCode), $($response.StatusDescription)"
}
else {
Exit-Script "#### Error accessing ${OpenSSLHomePage}: $message"
Exit-Script "#### Error accessing ${PackageList}: $message"
}
}
$config = ConvertFrom-Json $Response.Content

# Download and install MSI packages for 32 and 64 bit.
foreach ($bits in @(32, 64)) {

# Get the URL of the MSI installer from the JSON config.
$Url = $config.files | Get-Member | ForEach-Object {
$name = $_.name
$info = $config.files.$($_.name)
if (-not $info.light -and $info.installer -like "msi" -and $info.bits -eq $bits -and $info.arch -like "intel") {
$info.url
}
} | Select-Object -Last 1
if (-not $Url) {
Exit-Script "#### No MSI installer found for Win${bits}"
}

# Parse HTML page to locate the latest MSI files.
$Ref32 = $response.Links.href | Where-Object { $_ -like "*/Win32OpenSSL-*.msi" } | Select-Object -First 1
$Ref64 = $response.Links.href | Where-Object { $_ -like "*/Win64OpenSSL-*.msi" } | Select-Object -First 1

# Build the absolute URL's from base URL (the download page) and href links.
$Url32 = New-Object -TypeName 'System.Uri' -ArgumentList ([System.Uri]$OpenSSLHomePage, $Ref32)
$Url64 = New-Object -TypeName 'System.Uri' -ArgumentList ([System.Uri]$OpenSSLHomePage, $Ref64)

# Download and install one MSI package.
function Download-Install([string]$Url)
{
$MsiName = (Split-Path -Leaf $Url.toString())
$MsiName = (Split-Path -Leaf $Url)
$MsiPath = "$TmpDir\$MsiName"

if (-not $ForceDownload -and (Test-Path $MsiPath)) {
Expand All @@ -113,7 +137,4 @@ function Download-Install([string]$Url)
}
}

# Download and install the two MSI packages.
Download-Install $Url32
Download-Install $Url64
Exit-Script
18 changes: 8 additions & 10 deletions scripts/win-installer/libsrt.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ Caption "SRT Libraries Installer"
!define ProductName "libsrt"
!define Build32Dir "${BuildRoot}\build.Win32"
!define Build64Dir "${BuildRoot}\build.x64"
!define SSL32Dir "C:\Program Files (x86)\OpenSSL-Win32"
!define SSL64Dir "C:\Program Files\OpenSSL-Win64"

; Installer file information.
VIProductVersion ${VersionInfo}
Expand Down Expand Up @@ -142,26 +140,26 @@ Section "Install"
CreateDirectory "$INSTDIR\lib\Release-x64"
SetOutPath "$INSTDIR\lib\Release-x64"
File /oname=srt.lib "${Build64Dir}\Release\srt_static.lib"
File /oname=libcrypto.lib "${SSL64Dir}\lib\VC\static\libcrypto64MD.lib"
File /oname=libssl.lib "${SSL64Dir}\lib\VC\static\libssl64MD.lib"
File /oname=libcrypto.lib "${libcrypto64MD}"
File /oname=libssl.lib "${libssl64MD}"

CreateDirectory "$INSTDIR\lib\Debug-x64"
SetOutPath "$INSTDIR\lib\Debug-x64"
File /oname=srt.lib "${Build64Dir}\Debug\srt_static.lib"
File /oname=libcrypto.lib "${SSL64Dir}\lib\VC\static\libcrypto64MDd.lib"
File /oname=libssl.lib "${SSL64Dir}\lib\VC\static\libssl64MDd.lib"
File /oname=libcrypto.lib "${libcrypto64MDd}"
File /oname=libssl.lib "${libssl64MDd}"

CreateDirectory "$INSTDIR\lib\Release-Win32"
SetOutPath "$INSTDIR\lib\Release-Win32"
File /oname=srt.lib "${Build32Dir}\Release\srt_static.lib"
File /oname=libcrypto.lib "${SSL32Dir}\lib\VC\static\libcrypto32MD.lib"
File /oname=libssl.lib "${SSL32Dir}\lib\VC\static\libssl32MD.lib"
File /oname=libcrypto.lib "${libcrypto32MD}"
File /oname=libssl.lib "${libssl32MD}"

CreateDirectory "$INSTDIR\lib\Debug-Win32"
SetOutPath "$INSTDIR\lib\Debug-Win32"
File /oname=srt.lib "${Build32Dir}\Debug\srt_static.lib"
File /oname=libcrypto.lib "${SSL32Dir}\lib\VC\static\libcrypto32MDd.lib"
File /oname=libssl.lib "${SSL32Dir}\lib\VC\static\libssl32MDd.lib"
File /oname=libcrypto.lib "${libcrypto32MDd}"
File /oname=libssl.lib "${libssl32MDd}"

; Add an environment variable to installation root.
WriteRegStr HKLM ${EnvironmentKey} "LIBSRT" "$INSTDIR"
Expand Down
8 changes: 4 additions & 4 deletions srtcore/buffer_rcv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1096,12 +1096,12 @@ void CRcvBuffer::applyGroupDrift(const steady_clock::time_point& timebase,

CRcvBuffer::time_point CRcvBuffer::getTsbPdTimeBase(uint32_t usPktTimestamp) const
{
return m_tsbpd.getTsbPdTimeBase(usPktTimestamp);
return m_tsbpd.getBaseTime(usPktTimestamp);
}

void CRcvBuffer::updateTsbPdTimeBase(uint32_t usPktTimestamp)
{
m_tsbpd.updateTsbPdTimeBase(usPktTimestamp);
m_tsbpd.updateBaseTime(usPktTimestamp);
}

string CRcvBuffer::strFullnessState(int iFirstUnackSeqNo, const time_point& tsNow) const
Expand All @@ -1125,7 +1125,7 @@ string CRcvBuffer::strFullnessState(int iFirstUnackSeqNo, const time_point& tsNo
{
ss << ", timespan ";
const uint32_t usPktTimestamp = packetAt(iLastPos).getMsgTimeStamp();
ss << count_milliseconds(m_tsbpd.getPktTsbPdTime(usPktTimestamp) - nextValidPkt.tsbpd_time);
ss << count_milliseconds(m_tsbpd.getPktTime(usPktTimestamp) - nextValidPkt.tsbpd_time);
ss << " ms";
}
}
Expand All @@ -1142,7 +1142,7 @@ string CRcvBuffer::strFullnessState(int iFirstUnackSeqNo, const time_point& tsNo

CRcvBuffer::time_point CRcvBuffer::getPktTsbPdTime(uint32_t usPktTimestamp) const
{
return m_tsbpd.getPktTsbPdTime(usPktTimestamp);
return m_tsbpd.getPktTime(usPktTimestamp);
}

/* Return moving average of acked data pkts, bytes, and timespan (ms) of the receive buffer */
Expand Down
24 changes: 16 additions & 8 deletions srtcore/group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,11 +447,13 @@ static bool operator!=(const struct linger& l1, const struct linger& l2)
template <class ValueType>
static void importOption(vector<CUDTGroup::ConfigItem>& storage, SRT_SOCKOPT optname, const ValueType& field)
{
ValueType default_opt = ValueType();
int default_opt_size = sizeof(ValueType);
ValueType opt = field;
if (!getOptDefault(optname, (&default_opt), (default_opt_size)) || default_opt != opt)
ValueType default_opt = ValueType();
static const int default_opt_size = sizeof(ValueType);
ValueType opt = field;
int opt_size = default_opt_size;
if (!getOptDefault(optname, (&default_opt), (opt_size)) || default_opt != opt)
{
SRT_ASSERT(opt_size == default_opt_size);
// Store the option when:
// - no default for this option is found
// - the option value retrieved from the field is different than default
Expand Down Expand Up @@ -515,7 +517,11 @@ void CUDTGroup::deriveSettings(CUDT* u)
IM(SRTO_UDP_RCVBUF, iUDPRcvBufSize);
// SRTO_RENDEZVOUS: impossible to have it set on a listener socket.
// SRTO_SNDTIMEO/RCVTIMEO: groupwise setting
IM(SRTO_CONNTIMEO, tdConnTimeOut);

// SRTO_CONNTIMEO requires a special handling, because API stores the value in integer milliseconds,
// but the type of the variable is srt::sync::duration.
importOption(m_config, SRTO_CONNTIMEO, (int) count_milliseconds(u->m_config.tdConnTimeOut));

IM(SRTO_DRIFTTRACER, bDriftTracer);
// Reuseaddr: true by default and should only be true.
IM(SRTO_MAXBW, llMaxBW);
Expand All @@ -528,7 +534,9 @@ void CUDTGroup::deriveSettings(CUDT* u)
IM(SRTO_RCVLATENCY, iRcvLatency);
IM(SRTO_PEERLATENCY, iPeerLatency);
IM(SRTO_SNDDROPDELAY, iSndDropDelay);
IM(SRTO_PAYLOADSIZE, zExpPayloadSize);
// Special handling of SRTO_PAYLOADSIZE becuase API stores the value as int32_t,
// while the config structure stores it as size_t.
importOption(m_config, SRTO_PAYLOADSIZE, (int)u->m_config.zExpPayloadSize);
IMF(SRTO_TLPKTDROP, m_bTLPktDrop);

importOption(m_config, SRTO_STREAMID, u->m_config.sStreamName.str());
Expand All @@ -542,7 +550,7 @@ void CUDTGroup::deriveSettings(CUDT* u)

importOption(m_config, SRTO_PACKETFILTER, u->m_config.sPacketFilterConfig.str());

importOption(m_config, SRTO_PBKEYLEN, u->m_pCryptoControl->KeyLen());
importOption(m_config, SRTO_PBKEYLEN, (int) u->m_pCryptoControl->KeyLen());

// Passphrase is empty by default. Decipher the passphrase and
// store as passphrase option
Expand Down Expand Up @@ -822,7 +830,7 @@ void CUDTGroup::getOpt(SRT_SOCKOPT optname, void* pw_optval, int& w_optlen)
if (w_optlen < int(i->value.size()))
throw CUDTException(MJ_NOTSUP, MN_XSIZE, 0);

w_optlen = i->value.size();
w_optlen = (int) i->value.size();
memcpy((pw_optval), &i->value[0], i->value.size());
}

Expand Down
Loading

0 comments on commit 1852d48

Please sign in to comment.