
ForwardOpen event
Fires when port forwarding is open.
Type
Boolean.Syntax
- C#
- C++
- VB.NET
delegate bool devP2P.ForwardOpenEvent(IntPtr Handle, int forwardid, int forwardtype, string localaddress, int localport, string remoteaddress, int remoteport);
The ForwardOpen(Handle,forwid,forwardtype,localaddress,localport,remoteaddress,remoteport) syntax has these parts:
The ForwardOpen(Handle,forwid,forwardtype,localaddress,localport,remoteaddress,remoteport) syntax has these parts:
Handle | Reference to the devP2P instance. |
forwid | Forwarding channel index (0-31). |
forwardtype | ForwardTypes value, type of the forward. |
localaddress | Local address that is used for forwarding. |
localport | Local port that is used for forwarding. |
remoteaddress | Remote address that is used for forwarding. |
remoteport | Remote port that is used for forwarding. |
Return value | Return true if you accept the forwarding. If you return False, it will be cancelled. |
bool ForwardOpen(CP2P *p2p, int forwid, ForwardTypes type, char *localaddress, int localport, char *remoteaddress, int remoteport);
The ForwardOpen(p2p,forwid,type,localaddress,localport,remoteaddress,remoteport) syntax has these parts:
The ForwardOpen(p2p,forwid,type,localaddress,localport,remoteaddress,remoteport) syntax has these parts:
p2p | Pointer to devP2P instance that fired the event. |
forwid | Forwarding channel index (0-31). |
type | ForwardTypes value, type of the forward. |
localaddress | Local address that is used for forwarding. |
localport | Local port that is used for forwarding. |
remoteaddress | Remote address that is used for forwarding. |
remoteport | Remote port that is used for forwarding. |
Return value | Return true if you accept the forwarding. If you return False, it will be cancelled. |
Delegate Function P2P_ForwardOpenEvent(ByVal Handle As IntPtr, ByVal forwardid As Integer, ByVal type As Integer, ByVal localaddress As String, ByVal localport As Integer, ByVal remoteaddress As String, ByVal remoteport As Integer) As Boolean
The ForwardOpen(handle,forwid,forwardtype,localaddress,localport,remoteaddress,remoteport) syntax has these parts:
The ForwardOpen(handle,forwid,forwardtype,localaddress,localport,remoteaddress,remoteport) syntax has these parts:
handle | Reference to the devP2P instance. |
forwid | Forwarding channel index (0-31). |
forwardtype | ForwardTypes value, type of the forward. |
localaddress | Local address that is used for forwarding. |
localport | Local port that is used for forwarding. |
remoteaddress | Remote address that is used for forwarding. |
remoteport | Remote port that is used for forwarding. |
Return value | Return true if you accept the forwarding. If you return False, it will be cancelled. |
Remarks
ForwardOpen event fires when either local or remote peer has requested certain port to be forwarded to remote side. For most types both localaddress/port and remoteaddress/port must be set, and forwarding is made fixed->fixed ports. In such cases all arguments have real values. For SOCKS and HTTP forwards, remoteaddress is not known since it depends on user's request, so final information about the forward will be known in UserConnected event.You can use GetForward method to obtain information about forwarding with specified forwid index. Forwarding does not use any channels yet - as users are connecting, they will be taking free channels, and releasing them when they disconnect.
One forwarding can accept many users at once. For each user that connects to this forwarding, UserConnected event will fire so you can track users and deny access based on your set of rules.
To use this event, you should implement function by yourself in the code (based on function declaration), and set devP2P.Events.ForwardOpen structure member to point to your function.
Code sample
- C++
bool p2p_ForwardOpen(devP2Plib::CP2P *p2p, int forwid, devP2Plib::ForwardTypes type, char *localaddress, int localport, char *remoteaddress, int remoteport)
{
const char *t = "Unknown";
switch (type)
{
case devP2Plib::TCPLocalListen: t="TCPLocalListen";break;
case devP2Plib::TCPRemoteListen: t="TCPRemoteListen";break;
case devP2Plib::UDPLocalListen: t="UDPLocalListen";break;
case devP2Plib::UDPRemoteListen: t="UDPRemoteListen";break;
case devP2Plib::TCPSocksProxy: t="TCPSocksProxy";break;
case devP2Plib::TCPHttpProxy: t="TCPHttpProxy";break;
}
printf("%s] Forward %s open from %s (%d) ==> %s (%d)\r\n", p2p->MyName, t, localaddress, localport, remoteaddress, remoteport);
return true;
}
int main(int argc, char **argv)
{
/* ... */
devP2Plib::CP2P *p1 = devP2Plib::CP2P::Create();
/* ... */
p1->Events.ForwardOpen = p2p_ForwardOpen;
/* ... */
}
{
const char *t = "Unknown";
switch (type)
{
case devP2Plib::TCPLocalListen: t="TCPLocalListen";break;
case devP2Plib::TCPRemoteListen: t="TCPRemoteListen";break;
case devP2Plib::UDPLocalListen: t="UDPLocalListen";break;
case devP2Plib::UDPRemoteListen: t="UDPRemoteListen";break;
case devP2Plib::TCPSocksProxy: t="TCPSocksProxy";break;
case devP2Plib::TCPHttpProxy: t="TCPHttpProxy";break;
}
printf("%s] Forward %s open from %s (%d) ==> %s (%d)\r\n", p2p->MyName, t, localaddress, localport, remoteaddress, remoteport);
return true;
}
int main(int argc, char **argv)
{
/* ... */
devP2Plib::CP2P *p1 = devP2Plib::CP2P::Create();
/* ... */
p1->Events.ForwardOpen = p2p_ForwardOpen;
/* ... */
}
Platforms
WindowsMac OSX
Linux
BSD