author | Tero Marttila <terom@fixme.fi> |
Fri, 16 Jan 2009 22:03:49 +0200 | |
changeset 400 | d64bf28c4340 |
parent 286 | 2a8f20a53ff2 |
child 431 | c6d7272a164b |
permissions | -rw-r--r-- |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
1 |
#ifndef NETWORK_NODE_HH |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
2 |
#define NETWORK_NODE_HH |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
3 |
|
400
d64bf28c4340
more documentation tweaking, all Network/ files now have a @file comment. Fix Platform.h -> Platform.hh, and Buffer.hh + Packet.cc
Tero Marttila <terom@fixme.fi>
parents:
286
diff
changeset
|
4 |
/** |
d64bf28c4340
more documentation tweaking, all Network/ files now have a @file comment. Fix Platform.h -> Platform.hh, and Buffer.hh + Packet.cc
Tero Marttila <terom@fixme.fi>
parents:
286
diff
changeset
|
5 |
* @file |
d64bf28c4340
more documentation tweaking, all Network/ files now have a @file comment. Fix Platform.h -> Platform.hh, and Buffer.hh + Packet.cc
Tero Marttila <terom@fixme.fi>
parents:
286
diff
changeset
|
6 |
* |
d64bf28c4340
more documentation tweaking, all Network/ files now have a @file comment. Fix Platform.h -> Platform.hh, and Buffer.hh + Packet.cc
Tero Marttila <terom@fixme.fi>
parents:
286
diff
changeset
|
7 |
* Remote NetworkSessions |
d64bf28c4340
more documentation tweaking, all Network/ files now have a @file comment. Fix Platform.h -> Platform.hh, and Buffer.hh + Packet.cc
Tero Marttila <terom@fixme.fi>
parents:
286
diff
changeset
|
8 |
*/ |
d64bf28c4340
more documentation tweaking, all Network/ files now have a @file comment. Fix Platform.h -> Platform.hh, and Buffer.hh + Packet.cc
Tero Marttila <terom@fixme.fi>
parents:
286
diff
changeset
|
9 |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
10 |
// forward-declare |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
11 |
class NetworkNode; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
12 |
|
286 | 13 |
/** |
14 |
* Used to differentiate between different kinds of nodes in NetworkSession::build_node |
|
15 |
* |
|
16 |
* @see NetworkSession::build_node |
|
17 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
18 |
enum NetworkNodeType { |
286 | 19 |
NETWORK_NODE_SERVER_CLIENT, //<<< A server's client |
20 |
NETWORK_NODE_CLIENT_SERVER //<<< A client's server |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
21 |
}; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
22 |
|
186 | 23 |
#include "TCP.hh" |
24 |
#include "UDP.hh" |
|
25 |
#include "Session.hh" |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
26 |
|
286 | 27 |
/** |
28 |
* A NetworkNode represents a remote NetworkSession connected to our NetworkSession. |
|
29 |
* |
|
30 |
* A NetworkNode has a tcp connection, plus an udp socket to us (either NetworkSession's udp_srv or udp_client) |
|
31 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
32 |
class NetworkNode { |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
33 |
private: |
286 | 34 |
/** |
35 |
* Our local NetworkSession |
|
36 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
37 |
NetworkSession &session; |
286 | 38 |
|
39 |
/** |
|
40 |
* The TCP connection |
|
41 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
42 |
NetworkTCPTransport *tcp; |
286 | 43 |
|
44 |
/** |
|
45 |
* Our NetworkSession's UDP socket that we should use to send UDP packets to this node |
|
46 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
47 |
NetworkUDP *udp; |
286 | 48 |
|
49 |
/** |
|
50 |
* This address that the node connected from using TCP, used to associate received UDP packets with this node |
|
51 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
52 |
const NetworkAddress address; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
53 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
54 |
CL_SlotContainer slots; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
55 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
56 |
public: |
286 | 57 |
/** |
58 |
* Construct a new NetworkNode from the given tcp/udp sockets and address |
|
59 |
* |
|
60 |
* @param session our NetworkSession |
|
61 |
* @param tcp this node's TCP socket |
|
62 |
* @param udp the UDP socket to use for outgoing packets |
|
63 |
* @param address the remote address |
|
64 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
65 |
NetworkNode (NetworkSession &session, NetworkTCPTransport *tcp, NetworkUDP *udp, const NetworkAddress &address); |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
66 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
67 |
private: |
286 | 68 |
/** |
69 |
* Node should not be copied |
|
70 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
71 |
NetworkNode (const NetworkNode ©); |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
72 |
~NetworkNode (void); |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
73 |
NetworkNode& operator= (const NetworkNode ©); |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
74 |
|
286 | 75 |
/** |
76 |
* Our TCP socket indicates disconnect, tell NetworkSession and trigger sig_disconnect |
|
77 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
78 |
void on_disconnect (void); |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
79 |
|
286 | 80 |
/** |
81 |
* Our disconnect signal |
|
82 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
83 |
CL_Signal_v0 _sig_disconnected; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
84 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
85 |
public: |
286 | 86 |
/** |
87 |
* Write to appropriate NetworkSession header to the given packet. Can be used to prepare packets for use with |
|
88 |
* send_raw. The size of the header is equal to NETWORK_SESSION_HEADER_SIZE |
|
89 |
* |
|
90 |
* @param pkt the packet to write the header to |
|
91 |
* @param channel_id the NetworkChannelID to use |
|
92 |
* |
|
93 |
* @see send_raw |
|
94 |
* @see NETWORK_SESSION_HEADER_SIZE |
|
95 |
*/ |
|
202 | 96 |
void write_packet_header (NetworkPacketOutput &pkt, NetworkChannelID channel_id); |
286 | 97 |
|
98 |
/** |
|
99 |
* Send a raw packet prepared using write_packet_header. This does not need to copy the packet data around. |
|
100 |
* |
|
101 |
* @param pkt the NetworkPacket prepared using write_packet_header |
|
102 |
* @param reliable Whether to use TCP or UDP |
|
103 |
* |
|
104 |
* @see write_packet_header |
|
105 |
*/ |
|
106 |
void send_raw (const NetworkPacketBuffer &pkt, bool reliable = true); |
|
202 | 107 |
|
286 | 108 |
/** |
109 |
* Send the given packet to this node on the given channel. |
|
110 |
* |
|
111 |
* Note that this constructs a new *NetworkPacket* containing our header and the given packet, so there |
|
112 |
* given packet must be small enough to fit. |
|
113 |
* |
|
114 |
* @param channel_id the NetworkChannelID to use |
|
115 |
* @param pkt the NetworkPacket to send on the given channel |
|
116 |
* @param reliable Whether to use TCP or UDP |
|
117 |
*/ |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
118 |
void send (NetworkChannelID channel_id, const NetworkPacketBuffer &pkt, bool reliable = true); |
286 | 119 |
|
120 |
/** |
|
121 |
* Get this node's remote address (both TCP and UDP). |
|
122 |
* |
|
123 |
* @return NetworkAddress the remote address |
|
124 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
125 |
const NetworkAddress& getRemoteAddress (void); |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
126 |
|
286 | 127 |
/** |
128 |
* This node's TCP connection was lost, and the node has been removed from the NetworkSession's nodes list. |
|
129 |
* |
|
130 |
* Once this completes, the node will be destructed |
|
131 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
132 |
CL_Signal_v0& sig_disconnected (void) { return _sig_disconnected; } |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
133 |
}; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
134 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
135 |
#endif /* NETWORK_NODE_HH */ |