1 /* vim: set expandtab ts=4 sw=4: */ 2 /* 3 * You may redistribute this program and/or modify it under the terms of 4 * the GNU General Public License as published by the Free Software Foundation, 5 * either version 3 of the License, or (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * GNU General Public License for more details. 11 * 12 * You should have received a copy of the GNU General Public License 13 * along with this program. If not, see <https://www.gnu.org/licenses/>. 14 */ 15 #ifndef UpperDistributor_H 16 #define UpperDistributor_H 17 18 #include "dht/Address.h" 19 #include "memory/Allocator.h" 20 #include "net/EventEmitter.h" 21 #include "util/log/Log.h" 22 #include "util/Linker.h" 23 Linker_require("net/UpperDistributor.c") 24 25 /** 26 * Connects the TUN, DHT and IpTunnel (and other?) handlers to the SessionManager. 27 * All packets must have SessionManager_UpperHeader on them. 28 */ 29 struct UpperDistributor 30 { 31 struct Iface sessionManagerIf; 32 33 struct Iface tunAdapterIf; 34 35 struct Iface ipTunnelIf; 36 37 struct Iface controlHandlerIf; 38 }; 39 40 struct UpperDistributor_Handler 41 { 42 enum ContentType type; 43 int udpPort; 44 }; 45 46 /** If the regNum does not corrispond to an existing handler */ 47 #define UpperDistributor_unregisterHandler_NONEXISTANT -1 48 49 /** Returns 0 unless there is an error */ 50 int UpperDistributor_unregisterHandler(struct UpperDistributor* ud, int regNum); 51 52 /** 53 * Returns the number of elements in the list. 54 * If there are no elements, outputList is set to NULL. 55 */ 56 int UpperDistributor_listHandlers(struct UpperDistributor* ud, 57 struct UpperDistributor_Handler** outputList, 58 struct Allocator* alloc); 59 60 /** If the port has already been registered to a different contentType */ 61 #define UpperDistributor_registerHandler_PORT_REGISTERED -1 62 63 /** 64 * Register a handler for receiving messages of a given contentType. 65 * @return 0 unless there is an error. 66 */ 67 int UpperDistributor_registerHandler(struct UpperDistributor* ud, 68 enum ContentType ct, 69 int udpPort); 70 71 struct UpperDistributor* UpperDistributor_new(struct Allocator* alloc, 72 struct Log* log, 73 struct EventEmitter* ee, 74 struct Address* myAddress); 75 76 #endif 77