forked from n7tae/mrefd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprotocol.h
More file actions
112 lines (88 loc) · 3.21 KB
/
protocol.h
File metadata and controls
112 lines (88 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//
// cprotocol.h
// mrefd
//
// Created by Jean-Luc Deltombe (LX3JL) on 01/11/2015.
// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved.
// Copyright © 2020 Thomas A. Early, N7TAE
//
// ----------------------------------------------------------------------------
// This file is part of mrefd.
//
// mrefd is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// mrefd is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Foobar. If not, see <http://www.gnu.org/licenses/>.
// ----------------------------------------------------------------------------
#pragma once
#include "udpsocket.h"
#include "packetstream.h"
#include "packet.h"
////////////////////////////////////////////////////////////////////////////////////////
// class
class CProtocol
{
public:
// constructor
CProtocol();
// destructor
virtual ~CProtocol();
// initialization
virtual bool Initialize(const int ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6);
virtual void Close(void);
// queue
CPacketQueue *GetQueue(void) { m_Queue.Lock(); return &m_Queue; }
void ReleaseQueue(void) { m_Queue.Unlock(); }
// get
const CCallsign &GetReflectorCallsign(void)const { return m_ReflectorCallsign; }
// task
void Thread(void);
virtual void Task(void) = 0;
protected:
// packet encoding helpers
virtual bool EncodeDvHeaderPacket(const CPacket &, uint8_t *) const { return false; }
virtual bool EncodeDvFramePacket(const CPacket &, uint8_t *) const { return false; }
virtual bool EncodeDvLastFramePacket(const CPacket &, uint8_t *) const { return false; }
// stream helpers
virtual void OnPacketIn(std::unique_ptr<CPacket> &, const CIp &);
// stream handle helpers
CPacketStream *GetStream(uint16_t, const CIp &);
void CheckStreamsTimeout(void);
// queue helper
virtual void HandleQueue(void) = 0;
// keepalive helpers
virtual void HandleKeepalives(void) = 0;
// syntax helper
bool IsNumber(char) const;
bool IsLetter(char) const;
bool IsSpace(char) const;
ssize_t Receive6(uint8_t *buf, CIp &Ip, int time_ms);
ssize_t Receive4(uint8_t *buf, CIp &Ip, int time_ms);
ssize_t ReceiveDS(uint8_t *buf, CIp &Ip, int time_ms);
void Send(const char *buf, const CIp &Ip) const;
void Send(const uint8_t *buf, size_t size, const CIp &Ip) const;
void Send(const char *buf, const CIp &Ip, uint16_t port) const;
void Send(const uint8_t *buf, size_t size, const CIp &Ip, uint16_t port) const;
// socket
CUdpSocket m_Socket4;
CUdpSocket m_Socket6;
// streams
std::list<CPacketStream *> m_Streams;
// queue
CPacketQueue m_Queue;
// thread
std::atomic<bool> keep_running;
std::future<void> m_Future;
// identity
CCallsign m_ReflectorCallsign;
// debug
CTimePoint m_DebugTimer;
};