Luanti 5.10.0-dev
 
Loading...
Searching...
No Matches
connection.h
Go to the documentation of this file.
1// Minetest
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
6#include "irrlichttypes.h"
7#include "socket.h"
8#include "networkprotocol.h" // session_t
9
10class NetworkPacket;
11class PeerHandler;
12
13namespace con
14{
15
24
33
34class IPeer {
35public:
36 // Unique id of the peer
38
39 virtual const Address &getAddress() const = 0;
40
41protected:
42 IPeer(session_t id) : id(id) {}
43 ~IPeer() {}
44};
45
47{
48public:
49 virtual ~IConnection() = default;
50
51 virtual void Serve(Address bind_addr) = 0;
52 virtual void Connect(Address address) = 0;
53 virtual bool Connected() = 0;
54 virtual void Disconnect() = 0;
55 virtual void DisconnectPeer(session_t peer_id) = 0;
56
57 virtual bool ReceiveTimeoutMs(NetworkPacket *pkt, u32 timeout_ms) = 0;
59 return ReceiveTimeoutMs(pkt, 0);
60 }
61
62 virtual void Send(session_t peer_id, u8 channelnum, NetworkPacket *pkt, bool reliable) = 0;
63
64 virtual session_t GetPeerID() const = 0;
65 virtual Address GetPeerAddress(session_t peer_id) = 0;
66 virtual float getPeerStat(session_t peer_id, rtt_stat_type type) = 0;
67 virtual float getLocalStat(rate_stat_type type) = 0;
68};
69
70// MTP = Minetest Protocol
71IConnection *createMTP(float timeout, bool ipv6, PeerHandler *handler);
72
73} // namespace
Definition address.h:28
Definition networkpacket.h:14
Definition connection.h:47
virtual session_t GetPeerID() const =0
virtual void DisconnectPeer(session_t peer_id)=0
virtual void Serve(Address bind_addr)=0
bool TryReceive(NetworkPacket *pkt)
Definition connection.h:58
virtual bool ReceiveTimeoutMs(NetworkPacket *pkt, u32 timeout_ms)=0
virtual void Disconnect()=0
virtual float getPeerStat(session_t peer_id, rtt_stat_type type)=0
virtual void Send(session_t peer_id, u8 channelnum, NetworkPacket *pkt, bool reliable)=0
virtual ~IConnection()=default
virtual Address GetPeerAddress(session_t peer_id)=0
virtual float getLocalStat(rate_stat_type type)=0
virtual void Connect(Address address)=0
virtual bool Connected()=0
Definition connection.h:34
~IPeer()
Definition connection.h:43
virtual const Address & getAddress() const =0
IPeer(session_t id)
Definition connection.h:42
const session_t id
Definition connection.h:37
Definition peerhandler.h:13
Definition client.h:59
rate_stat_type
Definition connection.h:25
@ CUR_LOSS_RATE
Definition connection.h:30
@ AVG_INC_RATE
Definition connection.h:29
@ CUR_INC_RATE
Definition connection.h:28
@ CUR_DL_RATE
Definition connection.h:26
@ AVG_DL_RATE
Definition connection.h:27
@ AVG_LOSS_RATE
Definition connection.h:31
rtt_stat_type
Definition connection.h:16
@ MAX_RTT
Definition connection.h:18
@ MAX_JITTER
Definition connection.h:21
@ AVG_JITTER
Definition connection.h:22
@ MIN_JITTER
Definition connection.h:20
@ MIN_RTT
Definition connection.h:17
@ AVG_RTT
Definition connection.h:19
IConnection * createMTP(float timeout, bool ipv6, PeerHandler *handler)
Definition connection.cpp:10
u16 session_t
Definition networkprotocol.h:22