Skip to content
This repository
tree: cb6e137dac
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 87 lines (80 sloc) 3.925 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
/* vim: set expandtab ts=4 sw=4: */
/*
* You may redistribute this program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UDPInterface_H
#define UDPInterface_H

#include "interface/Interface.h"
#include "interface/InterfaceController.h"
#include "memory/Allocator.h"
#include "util/events/EventBase.h"
#include "util/log/Log.h"

struct UDPInterface
{
    struct Interface generic;

    /** Used for testing. */
    uint16_t boundPort_be;
};

/**
* @param base the LibEvent context.
* @param bindAddr a string representation of the address to bind to such as "0.0.0.0:12345".
* @param allocator the memory allocator for this message.
* @param exHandler the handler to deal with whatever exception arises.
* Exceptions:
* UDPInterface_new_PARSE_ADDRESS_FAILED Couldn't parse bindAddr as an ip address and port
* UDPInterface_new_FAILED_CREATING_EVENT Failed creating the event or registering it with
* the libevent event base (shouldn't happen)
* UDPInterface_new_SOCKET_FAILED Failed calling socket(), check EVUTIL_SOCKET_ERROR()
* UDPInterface_new_PROTOCOL_NOT_SUPPORTED Only IPv4 is supported as an underlying protocol
* UDPInterface_new_BIND_FAILED Failed calling bind(), check EVUTIL_SOCKET_ERROR()
*
* @param logger
* @param ic the controller which this interface should register with
* and use when starting connections.
* @return a new UDPInterface.
*/
#define UDPInterface_new_PARSE_ADDRESS_FAILED -1
#define UDPInterface_new_FAILED_CREATING_EVENT -2
#define UDPInterface_new_SOCKET_FAILED -3
#define UDPInterface_new_PROTOCOL_NOT_SUPPORTED -4
#define UDPInterface_new_BIND_FAILED -5
struct UDPInterface* UDPInterface_new(struct event_base* base,
                                      const char* bindAddr,
                                      struct Allocator* allocator,
                                      struct Except* exHandler,
                                      struct Log* logger,
                                      struct InterfaceController* ic);

/**
* Begin an outgoing connection.
*
* @param address the ipv4 address and udp port to connect to, expressed as address:port.
* @param cryptoKey the node's public key, this is required to send it traffic.
* @param password if specified, the password for authenticating with the other node.
* @param udpif the UDP interface.
* @return 0 on success
* UDPInterface_beginConnection_OUT_OF_SPACE if there is no space to store the entry.
* UDPInterface_beginConnection_BAD_KEY invalid (non-cjdns) cryptoKey
* UDPInterface_beginConnection_BAD_ADDRESS failed to parse ip address and port.
* UDPInterface_beginConnection_ADDRESS_MISMATCH address not same protocol as UDP socket.
* UDPInterface_beginConnection_UNKNOWN_ERROR something failed in InterfaceController.
*/
#define UDPInterface_beginConnection_OUT_OF_SPACE -1
#define UDPInterface_beginConnection_BAD_KEY -2
#define UDPInterface_beginConnection_BAD_ADDRESS -3
#define UDPInterface_beginConnection_ADDRESS_MISMATCH -4
#define UDPInterface_beginConnection_UNKNOWN_ERROR -5
int UDPInterface_beginConnection(const char* address,
                                 uint8_t cryptoKey[32],
                                 String* password,
                                 struct UDPInterface* udpif);

#endif
Something went wrong with that request. Please try again.