HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NET_MDNS.h
Go to the documentation of this file.
1 /*MIT License
2  *
3  * Copyright (c) 2020 Carlos Gomes Martinho
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy
6  * of this software and associated documentation files (the "Software"), to deal
7  * in the Software without restriction, including without limitation the rights
8  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9  * copies of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21  * SOFTWARE.
22  */
23 
24 #ifndef __NET_MDNS_H__
25 #define __NET_MDNS_H__
26 
27 #include "NET_API.h"
28 
29 #include <UT/UT_Array.h>
30 #include <UT/UT_NonCopyable.h>
31 #include <UT/UT_StringHolder.h>
32 
33 #include <thread>
34 #include <chrono>
35 
37 {
39  // Address
41  // Domain Name pointer
43  // Arbitrary text string
45  // IP6 Address [Thomson]
47  // Server Selection [RFC2782]
49 };
50 
52 {
57 };
58 
60 {
64 };
65 
67 {
68 public:
70  uint16_t myPort = 0;
71  uint16_t myPriority = 0;
72  uint16_t myWeight = 0;
73 };
74 
76 {
77 public:
78  // Identity is the service endpoint. myEntry cannot serve as one: the parse
79  // callback rewrites it for every record in the datagram, so what it holds
80  // afterwards is whichever record the responder happened to put last, not
81  // the service that answered.
82  bool operator==(const NET_mDNSQueryResult &other) const
83  {
84  return mySRV.myName == other.mySRV.myName
85  && mySRV.myPort == other.mySRV.myPort;
86  }
87  bool operator!=(const NET_mDNSQueryResult &other) const
88  {
89  return !(*this == other);
90  }
91 
96 };
97 
99 {
100 public:
102  myHostname("nobody"),
103  myName("_http._tcp.local."),
104  myTxtRecord(),
105  myHasIpv4(false),
106  myHasIpv6(false),
107  myServiceAddressIpv4(0)
108  {
109  memset(myServiceAddressIpv6, 0, sizeof(myServiceAddressIpv6));
110  }
111  ~NET_mDNS();
112 
114 
115 #if 0
116  bool isServiceRunning() { return myIsRunning; }
117  void setServiceHostname(const UT_StringHolder &hostname)
118  {
119  myHostname = hostname;
120  }
121  void setServicePort(std::uint16_t port) { myPort = port; }
122  void setServiceName(const UT_StringHolder &name) { myName = name; }
123  void setServiceTxtRecord(const UT_StringHolder &txt_record)
124  {
125  myTxtRecord = txt_record;
126  }
127  void startService();
128  void stopService();
129 #endif
130  void executeQuery(
131  const UT_StringHolder &service,
133  const std::chrono::milliseconds &max_query_time,
135 #if 0
136  void executeDiscovery();
137 #endif
138 private:
139 #if 0
140  void runMainLoop();
141  int openServiceSockets(int *sockets, int max_sockets);
142 
143  std::thread worker_thread_;
144  std::uint16_t myPort;
145  bool myIsRunning;
146 #endif
147  int openClientSockets(
148  int *sockets,
149  int max_sockets,
150  int port,
151  NET_mDNSIpFilter ip_filter);
152 
153  UT_StringHolder myHostname;
154  UT_StringHolder myName;
155  UT_StringHolder myTxtRecord;
156 
157  bool myHasIpv4;
158  bool myHasIpv6;
159 
160  uint32_t myServiceAddressIpv4;
161  uint8_t myServiceAddressIpv6[16];
162 };
163 
164 #endif // __NET_MDNS_H__
165 
UT_StringHolder myFromAddr
Definition: NET_MDNS.h:94
uint16_t myPort
Definition: NET_MDNS.h:70
UT_StringHolder myName
Definition: NET_MDNS.h:69
bool operator==(const NET_mDNSQueryResult &other) const
Definition: NET_MDNS.h:82
#define NET_API
Definition: NET_API.h:9
bool operator!=(const NET_mDNSQueryResult &other) const
Definition: NET_MDNS.h:87
NET_mDNSEntryType
Definition: NET_MDNS.h:51
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
GLuint const GLchar * name
Definition: glcorearb.h:786
NET_mDNSIpFilter
Definition: NET_MDNS.h:59
**Note that the tasks the is the thread number *for the or if it s being executed by a non pool thread(this *can happen in cases where the whole pool is occupied and the calling *thread contributes to running the work load).**Thread pool.Have fun
NET_mDNS()
Definition: NET_MDNS.h:101
UT_StringHolder myEntry
Definition: NET_MDNS.h:93
NET_mDNSRecordSRV mySRV
Definition: NET_MDNS.h:95
NET_mDNSRecordType
Definition: NET_MDNS.h:36