src/Network/Node.hh
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--
more documentation tweaking, all Network/ files now have a @file comment. Fix Platform.h -> Platform.hh, and Buffer.hh + Packet.cc
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
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    13
/**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    14
 * Used to differentiate between different kinds of nodes in NetworkSession::build_node
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    15
 *
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    16
 * @see NetworkSession::build_node
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    17
 */
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    18
enum NetworkNodeType {
286
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    19
    NETWORK_NODE_SERVER_CLIENT,     //<<< A server's client
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    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
0738f2949a2b move src/Network% to src/Network/%
terom
parents: 185
diff changeset
    23
#include "TCP.hh"
0738f2949a2b move src/Network% to src/Network/%
terom
parents: 185
diff changeset
    24
#include "UDP.hh"
0738f2949a2b move src/Network% to src/Network/%
terom
parents: 185
diff changeset
    25
#include "Session.hh"
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    26
286
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    27
/**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    28
 * A NetworkNode represents a remote NetworkSession connected to our NetworkSession.
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    29
 *
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    30
 * A NetworkNode has a tcp connection, plus an udp socket to us (either NetworkSession's udp_srv or udp_client)
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    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
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    34
        /**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    35
         * Our local NetworkSession
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    36
         */
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    37
        NetworkSession &session;
286
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    38
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    39
        /**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    40
         * The TCP connection
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    41
         */
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    42
        NetworkTCPTransport *tcp;
286
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    43
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    44
        /**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    45
         * Our NetworkSession's UDP socket that we should use to send UDP packets to this node
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    46
         */
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    47
        NetworkUDP *udp;
286
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    48
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    49
        /**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    50
         * This address that the node connected from using TCP, used to associate received UDP packets with this node
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    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
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    57
        /**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    58
         * Construct a new NetworkNode from the given tcp/udp sockets and address
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    59
         *
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    60
         * @param session our NetworkSession
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    61
         * @param tcp this node's TCP socket
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    62
         * @param udp the UDP socket to use for outgoing packets
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    63
         * @param address the remote address
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    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
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    68
        /**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    69
         * Node should not be copied
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    70
         */
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    71
        NetworkNode (const NetworkNode &copy);
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 &copy);
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    74
        
286
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    75
        /**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    76
         * Our TCP socket indicates disconnect, tell NetworkSession and trigger sig_disconnect
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    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
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    80
        /**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    81
         * Our disconnect signal
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    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
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    86
        /**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    87
         * Write to appropriate NetworkSession header to the given packet. Can be used to prepare packets for use with
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    88
         * send_raw. The size of the header is equal to NETWORK_SESSION_HEADER_SIZE
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    89
         *
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    90
         * @param pkt the packet to write the header to
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    91
         * @param channel_id the NetworkChannelID to use
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    92
         *
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    93
         * @see send_raw
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    94
         * @see NETWORK_SESSION_HEADER_SIZE
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    95
         */
202
b3f5d766391e support sending of raw packets
terom
parents: 200
diff changeset
    96
        void write_packet_header (NetworkPacketOutput &pkt, NetworkChannelID channel_id);
286
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    97
        
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    98
        /**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    99
         * Send a raw packet prepared using write_packet_header. This does not need to copy the packet data around.
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
   100
         *
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
   101
         * @param pkt the NetworkPacket prepared using write_packet_header
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
   102
         * @param reliable Whether to use TCP or UDP
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
   103
         *
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
   104
         * @see write_packet_header
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
   105
         */
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
   106
        void send_raw (const NetworkPacketBuffer &pkt, bool reliable = true);
202
b3f5d766391e support sending of raw packets
terom
parents: 200
diff changeset
   107
286
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
   108
        /**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
   109
         * Send the given packet to this node on the given channel.
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
   110
         *
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
   111
         * Note that this constructs a new *NetworkPacket* containing our header and the given packet, so there
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
   112
         * given packet must be small enough to fit.
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
   113
         *
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
   114
         * @param channel_id the NetworkChannelID to use
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
   115
         * @param pkt the NetworkPacket to send on the given channel
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
   116
         * @param reliable Whether to use TCP or UDP
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
   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
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
   119
        
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
   120
        /**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
   121
         * Get this node's remote address (both TCP and UDP).
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
   122
         *
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
   123
         * @return NetworkAddress the remote address
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
   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
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
   127
        /**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
   128
         * This node's TCP connection was lost, and the node has been removed from the NetworkSession's nodes list.
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
   129
         *
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
   130
         * Once this completes, the node will be destructed
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
   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 */