]> git.lizzy.rs Git - rudp.git/blob - rudp_punch.h
Switch to CMake
[rudp.git] / rudp_punch.h
1 #ifndef __rudp_punch_h__
2 #define __rudp_punch_h__
3
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7
8 #include "rudp.h"
9 #include "platform_adpt.h"
10
11 #define CONNSTATUS_CONNECTED    1       //connection is established
12 #define CONNSTATUS_ACCEPTED     2       //connection is accepted by server
13 #define CONNSTATUS_READABLE     3       //data arrived from peer
14
15 #define CHECKCONNECTION_OK              0
16 #define CHECKCONNECTION_CONTINUE        1
17 #define CHECKCONNECTION_FAKE            2
18 #define CHECKCONNECTION_RESETED         3
19 #define CHECKCONNECTION_
20 typedef int (*CHECKCONNECTIONCB)(RUDPSOCKET sock, int status, void *data);
21
22 /*
23  * \param local_port 
24  *      Local port the socket will bind to(but not listen on).
25  * \param listening_peer 
26  *      The address the other side listening on, may be NULL.
27  * \param candidate_peers, n_peer
28  *      The possible addresses the other side can be reached by.
29  */
30 //说明:
31 //      连接建立时,以 ACCEPTED(连接为对方Listening状态的套接字接受) 或 CONNECTED(Simultaneous connection成功) 
32 //      为 status 参数调用cb。 
33 //      对ACCEPTED的连接,cb应向对端发送事务标识,以区分此连接所属的事务(或会话).当此连接绑定传话后,接下来进入连接确认阶段.
34 //      对CONNECTED的连接,要进行连接确认。
35 //
36 //      因为穿透过程会同时发起多个连接,而最终只会选择一个成功连接。所以连接建立后要经双方确认, 然后才会关闭其它连接(过程),穿透过程中止。
37 //
38 //      确认阶段,其中一方选择一个(如最先建立的)连接,向另一方发送确认命令,确认后,双方关闭其它连接,使用确认的连接通信
39 //
40 //      cb返回OK,则连接得到确认,函数返回该连接;返回CONTINUE,则继续确认过程;返回其他值该连接并关闭。
41 //      当连接双方需要交换一些信息确认有效性时,cb向对端发送一些数据并返回 CHECKCONNECTION_CONTINUE。当对端应答到来时,
42 //      用status=SOCK_STATUS_READABLE再次调用cb
43 //
44 RUDPSOCKET RUDPPunch(unsigned short local_port, 
45                 const struct sockaddr *listening_peer, 
46                 const struct sockaddr_in *candidate_peers, int n_peer, 
47                 CHECKCONNECTIONCB cb, void *cb_data);
48
49
50 #ifdef __cplusplus
51 }
52 #endif
53
54 #endif
55