Skip to content

Commit

Permalink
use IPAndPortAddress and DWORD to store multiplex destinations and IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
willamowius committed Jan 4, 2018
1 parent 654fa2b commit 2180eaf
Show file tree
Hide file tree
Showing 7 changed files with 273 additions and 127 deletions.
138 changes: 72 additions & 66 deletions ProxyChannel.cxx

Large diffs are not rendered by default.

64 changes: 32 additions & 32 deletions ProxyChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// ProxyChannel.h
//
// Copyright (c) Citron Network Inc. 2001-2003
// Copyright (c) 2002-2017, Jan Willamowius
// Copyright (c) 2002-2018, Jan Willamowius
//
// This work is published under the GNU Public License version 2 (GPLv2)
// see file COPYING for details.
Expand Down Expand Up @@ -71,7 +71,7 @@ const WORD DEFAULT_PACKET_BUFFER_SIZE = 2048;

void PrintQ931(int, const char *, const char *, const Q931 *, const H225_H323_UserInformation *);

ssize_t UDPSendWithSourceIP(int fd, void * data, size_t len, const H323TransportAddress & toAddress);
ssize_t UDPSendWithSourceIP(int fd, void * data, size_t len, const IPAndPortAddress & toAddress);
ssize_t UDPSendWithSourceIP(int fd, void * data, size_t len, const PIPSocket::Address & ip, WORD port);


Expand Down Expand Up @@ -226,8 +226,8 @@ class UDPProxySocket : public UDPSocket, public ProxySocket {
bool UsesH46019() const { return m_useH46019; }
void SetH46019UniDirectional(bool val) { m_h46019uni = val; }
void AddKeepAlivePT(BYTE pt);
void SetMultiplexDestination(const H323TransportAddress & toAddress, H46019Side side);
void SetMultiplexID(PUInt32b multiplexID, H46019Side side);
void SetMultiplexDestination(const IPAndPortAddress & toAddress, H46019Side side);
void SetMultiplexID(DWORD multiplexID, H46019Side side);
void SetMultiplexSocket(int multiplexSocket, H46019Side side);
#endif

Expand Down Expand Up @@ -282,11 +282,11 @@ class UDPProxySocket : public UDPSocket, public ProxySocket {
PTime m_channelStartTime;
// two (!), one or zero parties in a call through a UDPProxySocket may by multiplexed
// UDPProxySocket always receives regular RTP, but may send out multiplexed
H323TransportAddress m_multiplexDestination_A; // OLC side of first logical channel in this session
PUInt32b m_multiplexID_A; // ID _to_ A side (only valid if m_multiplexDestination_A is set)
IPAndPortAddress m_multiplexDestination_A; // OLC side of first logical channel in this session
DWORD m_multiplexID_A; // ID _to_ A side (only valid if m_multiplexDestination_A is set)
int m_multiplexSocket_A; // only valid if m_multiplexDestination_A is set
H323TransportAddress m_multiplexDestination_B; // OLCAck side of first logical channel in this session
PUInt32b m_multiplexID_B; // ID _to_ B side (only valid if m_multiplexDestination_B is set)
IPAndPortAddress m_multiplexDestination_B; // OLCAck side of first logical channel in this session
DWORD m_multiplexID_B; // ID _to_ B side (only valid if m_multiplexDestination_B is set)
int m_multiplexSocket_B; // only valid if m_multiplexDestination_ is set)
PMutex m_multiplexMutex; // protect multiplex IDs, addresses and sockets against access from concurrent threads
#endif
Expand Down Expand Up @@ -412,7 +412,7 @@ class CallSignalSocket : public TCPProxySocket {
bool OnSCICall(const H225_CallIdentifier & callID, H225_TransportAddress sigAdr, bool useTLS);
bool IsCallFromTraversalServer() const { return m_callFromTraversalServer; }
bool IsCallToTraversalServer() const { return m_callToTraversalServer; }
void SetSessionMultiplexDestination(WORD session, bool isRTCP, const H323TransportAddress & toAddress, H46019Side side);
void SetSessionMultiplexDestination(WORD session, bool isRTCP, const IPAndPortAddress & toAddress, H46019Side side);
const H245Handler * GetH245Handler() const { return m_h245handler; }
#endif
void LockH245Handler() { m_h245handlerLock.Wait(); }
Expand Down Expand Up @@ -654,14 +654,14 @@ class H46019Session
void Dump() const;

bool IsValid() const { return !m_deleted && ((m_session != INVALID_RTP_SESSION) || (m_flcn > 0)); }
bool sideAReady(bool isRTCP) const { return isRTCP ? IsSet(m_addrA_RTCP) : IsSet(m_addrA); }
bool sideBReady(bool isRTCP) const { return isRTCP ? IsSet(m_addrB_RTCP) : IsSet(m_addrB); }
bool sideAReady(bool isRTCP) const { return isRTCP ? m_addrA_RTCP.IsSet() : m_addrA.IsSet(); }
bool sideBReady(bool isRTCP) const { return isRTCP ? m_addrB_RTCP.IsSet() : m_addrB.IsSet(); }
H46019Session SwapSides() const; // return a copy with side A and B swapped

static bool IsKeepAlive(unsigned len, bool isRTCP) { return isRTCP ? true : (len == 12); }

void HandlePacket(PUInt32b receivedMultiplexID, const H323TransportAddress & fromAddress, void * data, unsigned len, bool isRTCP);
static void Send(PUInt32b sendMultiplexID, const H323TransportAddress & toAddress, int ossocket, void * data, unsigned len, bool bufferHasRoomForID = false);
void HandlePacket(DWORD receivedMultiplexID, const IPAndPortAddress & fromAddress, void * data, unsigned len, bool isRTCP);
static void Send(DWORD sendMultiplexID, const IPAndPortAddress & toAddress, int ossocket, void * data, unsigned len, bool bufferHasRoomForID = false);

public:
//mutable PTimedMutex m_usedLock;
Expand All @@ -672,14 +672,14 @@ class H46019Session
WORD m_flcn; // only used to assign master assigned RTP session IDs
void * m_openedBy; // side A (pointer to H245ProxyHandler used as an ID)
void * m_otherSide; // side B (pointer to H245ProxyHandler used as an ID)
H323TransportAddress m_addrA;
H323TransportAddress m_addrA_RTCP;
H323TransportAddress m_addrB;
H323TransportAddress m_addrB_RTCP;
PUInt32b m_multiplexID_fromA;
PUInt32b m_multiplexID_toA;
PUInt32b m_multiplexID_fromB;
PUInt32b m_multiplexID_toB;
IPAndPortAddress m_addrA;
IPAndPortAddress m_addrA_RTCP;
IPAndPortAddress m_addrB;
IPAndPortAddress m_addrB_RTCP;
DWORD m_multiplexID_fromA;
DWORD m_multiplexID_toA;
DWORD m_multiplexID_fromB;
DWORD m_multiplexID_toB;
int m_osSocketToA;
int m_osSocketToA_RTCP;
int m_osSocketToB;
Expand All @@ -688,8 +688,8 @@ class H46019Session
#ifdef HAS_H235_MEDIA
RTPLogicalChannel * m_encryptingLC;
RTPLogicalChannel * m_decryptingLC;
PUInt32b m_encryptMultiplexID;
PUInt32b m_decryptMultiplexID;
DWORD m_encryptMultiplexID;
DWORD m_decryptMultiplexID;
#endif
};

Expand Down Expand Up @@ -728,16 +728,16 @@ class MultiplexedRTPHandler : public Singleton<MultiplexedRTPHandler> {
#endif
virtual void DumpChannels(const PString & msg = "") const;

virtual bool HandlePacket(PUInt32b receivedMultiplexID, const H323TransportAddress & fromAddress, void * data, unsigned len, bool isRTCP);
virtual bool HandlePacket(DWORD receivedMultiplexID, const IPAndPortAddress & fromAddress, void * data, unsigned len, bool isRTCP);
#ifdef HAS_H46026
virtual bool HandlePacket(const H225_CallIdentifier & callid, const H46026_UDPFrame & data);
#endif

virtual int GetRTPOSSocket() const { return m_reader ? m_reader->GetRTPOSSocket() : INVALID_OSSOCKET; }
virtual int GetRTCPOSSocket() const { return m_reader ? m_reader->GetRTCPOSSocket() : INVALID_OSSOCKET; }

virtual PUInt32b GetMultiplexID(const H225_CallIdentifier & callid, WORD session, void * to);
virtual PUInt32b GetNewMultiplexID();
virtual DWORD GetMultiplexID(const H225_CallIdentifier & callid, WORD session, void * to);
virtual DWORD GetNewMultiplexID();

bool GetDetectedMediaIP(const H225_CallIdentifier & callID, WORD sessionID, bool forCaller, /* out */ PIPSocket::Address & addr, WORD & port) const;

Expand All @@ -748,7 +748,7 @@ class MultiplexedRTPHandler : public Singleton<MultiplexedRTPHandler> {
MultiplexedRTPReader * m_reader;
mutable PReadWriteMutex m_listLock;
list<H46019Session> m_h46019channels;
PUInt32b idCounter; // we should make sure this counter is _not_ reset on reload
DWORD idCounter; // we should make sure this counter is _not_ reset on reload
GkTimerManager::GkTimerHandle m_cleanupTimer;
PTimeInterval m_deleteDelay; // how long to wait before deleting a session marked for delete
};
Expand All @@ -763,7 +763,7 @@ class H46026Session
public:
H46026Session() : m_isValid(false) { }
H46026Session(const H225_CallIdentifier & callid, WORD session, int osRTPSocket, int osRTCPSocket,
const H323TransportAddress & toRTP, const H323TransportAddress & toRTCP);
const IPAndPortAddress & toRTP, const IPAndPortAddress & toRTCP);

void Send(void * data, unsigned len, bool isRTCP);
bool IsValid() const { return m_isValid; }
Expand All @@ -774,8 +774,8 @@ class H46026Session
WORD m_session;
int m_osRTPSocket;
int m_osRTCPSocket;
H323TransportAddress m_toAddressRTP;
H323TransportAddress m_toAddressRTCP;
IPAndPortAddress m_toAddressRTP;
IPAndPortAddress m_toAddressRTCP;

#ifdef HAS_H235_MEDIA
RTPLogicalChannel * m_encryptingLC;
Expand All @@ -793,8 +793,8 @@ class H46026RTPHandler : public Singleton<H46026RTPHandler> {

virtual void AddChannel(const H46026Session & chan);
virtual void ReplaceChannel(const H46026Session & chan);
virtual void UpdateChannelRTP(const H225_CallIdentifier & callid, WORD session, H323TransportAddress toRTP);
virtual void UpdateChannelRTCP(const H225_CallIdentifier & callid, WORD session, H323TransportAddress toRTCP);
virtual void UpdateChannelRTP(const H225_CallIdentifier & callid, WORD session, IPAndPortAddress toRTP);
virtual void UpdateChannelRTCP(const H225_CallIdentifier & callid, WORD session, IPAndPortAddress toRTCP);
virtual void RemoveChannels(H225_CallIdentifier callid); // pass by value in case call gets removed
H46026Session FindSession(const H225_CallIdentifier & callid, WORD session) const;
#ifdef HAS_H235_MEDIA
Expand Down
22 changes: 11 additions & 11 deletions RasTbl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// bookkeeping for RAS-Server in H.323 gatekeeper
//
// Copyright (c) 2000-2017, Jan Willamowius
// Copyright (c) 2000-2018, Jan Willamowius
//
// This work is published under the GNU Public License version 2 (GPLv2)
// see file COPYING for details.
Expand Down Expand Up @@ -2529,7 +2529,7 @@ struct RTPKeepAliveFrame

struct MultiplexedRTPKeepAliveFrame
{
PUInt32b multiplexID;
DWORD multiplexID;
BYTE b1;
BYTE pt;
WORD seq;
Expand All @@ -2552,7 +2552,7 @@ struct RTCPKeepAliveFrame

struct MultiplexedRTCPKeepAliveFrame
{
PUInt32b multiplexID;
DWORD multiplexID;
BYTE b1;
BYTE pt;
WORD len;
Expand Down Expand Up @@ -4884,9 +4884,9 @@ void CallRec::H46024BSessionFlag(WORD sessionID)
m_h46024Bflag.push_back(sessionID);
}

void CallRec::H46024BInitiate(WORD sessionID, const H323TransportAddress & fwd, const H323TransportAddress & rev, unsigned muxID_fwd, unsigned muxID_rev)
void CallRec::H46024BInitiate(WORD sessionID, const IPAndPortAddress & fwd, const IPAndPortAddress & rev, unsigned muxID_fwd, unsigned muxID_rev)
{
if (fwd.IsEmpty() || rev.IsEmpty()) {
if (!fwd.IsSet() || !rev.IsSet()) {
PTRACE(4, "H46024B\tSession " << sessionID << " NAT offload probe not ready");
return;
}
Expand All @@ -4900,8 +4900,8 @@ void CallRec::H46024BInitiate(WORD sessionID, const H323TransportAddress & fwd,

PTRACE(5, "H46024B\tNAT offload probes S:" << sessionID << " F:" << fwd << " R:" << rev << " mux " << muxID_fwd << " " << muxID_rev);

PIPSocket::Address addr; rev.GetIpAddress(addr);
bool revDir = (GetCallSignalSocketCalled()->GetPeerAddr() == addr);
PIPSocket::Address addr = rev.GetIP();
bool revDir = (GetCallSignalSocketCalled()->GetPeerAddr() == addr);
//PTRACE(1, "SH\tNAT offload probe " << GetCallSignalSocketCalled()->GetPeerAddr() << " " << addr << " " << revDir);

H46024Balternate alt;
Expand Down Expand Up @@ -5017,7 +5017,7 @@ int CallRec::GetH46019Direction() const
return dir;
}

void CallRec::AddRTPKeepAlive(unsigned flcn, const H323TransportAddress & keepAliveRTPAddr, unsigned keepAliveInterval, PUInt32b multiplexID)
void CallRec::AddRTPKeepAlive(unsigned flcn, const IPAndPortAddress & keepAliveRTPAddr, unsigned keepAliveInterval, DWORD multiplexID)
{
H46019KeepAlive ka;
ka.type = RTP;
Expand Down Expand Up @@ -5051,12 +5051,12 @@ void CallRec::StartRTPKeepAlive(unsigned flcn, int RTPOSSocket)
}
}

void CallRec::AddRTCPKeepAlive(unsigned flcn, const H245_UnicastAddress & keepAliveRTCPAddr, unsigned keepAliveInterval, PUInt32b multiplexID)
void CallRec::AddRTCPKeepAlive(unsigned flcn, const H245_UnicastAddress & keepAliveRTCPAddr, unsigned keepAliveInterval, DWORD multiplexID)
{
H46019KeepAlive ka;
ka.type = RTCP;
ka.flcn = flcn;
ka.dest = H245UnicastToH323TransportAddr(keepAliveRTCPAddr);
ka.dest = keepAliveRTCPAddr;
ka.interval = keepAliveInterval;
ka.multiplexID = multiplexID;
m_RTCPkeepalives[flcn] = ka;
Expand Down Expand Up @@ -5086,7 +5086,7 @@ void CallRec::RemoveKeepAllAlives()
m_RTCPkeepalives.clear();
}

void CallRec::SetSessionMultiplexDestination(WORD session, void * openedBy, bool isRTCP, const H323TransportAddress & toAddress, H46019Side side)
void CallRec::SetSessionMultiplexDestination(WORD session, void * openedBy, bool isRTCP, const IPAndPortAddress & toAddress, H46019Side side)
{
// try to find LC for this session
if (m_callingSocket && (m_callingSocket->GetH245Handler() == openedBy)) {
Expand Down
16 changes: 8 additions & 8 deletions RasTbl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// bookkeeping for RAS-Server in H.323 gatekeeper
//
// Copyright (c) 2000-2017, Jan Willamowius
// Copyright (c) 2000-2018, Jan Willamowius
//
// This work is published under the GNU Public License version 2 (GPLv2)
// see file COPYING for details.
Expand Down Expand Up @@ -46,7 +46,7 @@ enum RerouteState { NoReroute, RerouteInitiated, Rerouting };
enum H46019Side { SideA, SideB };
const int INVALID_OSSOCKET = -1;
const WORD INVALID_RTP_SESSION = 0;
const PUInt32b INVALID_MULTIPLEX_ID = 0;
const DWORD INVALID_MULTIPLEX_ID = 0;
const BYTE GNUGK_KEEPALIVE_RTP_PAYLOADTYPE = 116; // must at least be 1 less than MAX_DYNAMIC_PAYLOAD_TYPE
const BYTE MIN_DYNAMIC_PAYLOAD_TYPE = 96;
const BYTE MAX_DYNAMIC_PAYLOAD_TYPE = 127;
Expand Down Expand Up @@ -676,11 +676,11 @@ class H46019KeepAlive

unsigned flcn;
KeepAliveType type;
H323TransportAddress dest;
IPAndPortAddress dest;
unsigned interval;
unsigned seq;
int ossocket;
PUInt32b multiplexID;
DWORD multiplexID;
BYTE payloadType;
GkTimerManager::GkTimerHandle timer;
};
Expand Down Expand Up @@ -856,7 +856,7 @@ class CallRec {
CallSignalSocket * H46024BSignalSocket(bool response);

/** Initiate Probe */
void H46024BInitiate(WORD sessionID, const H323TransportAddress & fwd, const H323TransportAddress & rev, unsigned muxID_fwd=0, unsigned muxID_rev=0);
void H46024BInitiate(WORD sessionID, const IPAndPortAddress & fwd, const IPAndPortAddress & rev, unsigned muxID_fwd = 0, unsigned muxID_rev = 0);

/** Response Probe */
void H46024BRespond();
Expand Down Expand Up @@ -1427,15 +1427,15 @@ class CallRec {
PBYTEArray RetrieveSetup();
int GetH46019Direction() const;

void AddRTPKeepAlive(unsigned flcn, const H323TransportAddress & keepAliveRTPAddr, unsigned keepAliveInterval, PUInt32b multiplexID);
void AddRTPKeepAlive(unsigned flcn, const IPAndPortAddress & keepAliveRTPAddr, unsigned keepAliveInterval, DWORD multiplexID);
void SetRTPKeepAlivePayloadType(unsigned flcn, BYTE payloadType);
void StartRTPKeepAlive(unsigned flcn, int RTPOSSocket);
void AddRTCPKeepAlive(unsigned flcn, const H245_UnicastAddress & keepAliveRTCPAddr, unsigned keepAliveInterval, PUInt32b multiplexID);
void AddRTCPKeepAlive(unsigned flcn, const H245_UnicastAddress & keepAliveRTCPAddr, unsigned keepAliveInterval, DWORD multiplexID);
void StartRTCPKeepAlive(unsigned flcn, int RTCPOSSocket);
void RemoveKeepAlives(unsigned flcn);
void RemoveKeepAllAlives();

void SetSessionMultiplexDestination(WORD session, void * openedBy, bool isRTCP, const H323TransportAddress & toAddress, H46019Side side);
void SetSessionMultiplexDestination(WORD session, void * openedBy, bool isRTCP, const IPAndPortAddress & toAddress, H46019Side side);
bool IgnoreSignaledIPs() const { return m_ignoreSignaledIPs; }
void SetIgnoreSignaledIPs(bool val) { m_ignoreSignaledIPs = val; }
#endif
Expand Down
Loading

0 comments on commit 2180eaf

Please sign in to comment.