Skip to content

Allow definition of custom network interfaces #921

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/NetworkClient.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once

#include <Client.h>
#include <WiFiClient.h>

class NetworkClient : public Client {
class Impl;
std::unique_ptr<Impl> _impl;

public:
NetworkClient();
NetworkClient(WiFiClient wifi_client);
virtual ~NetworkClient();

int connect(IPAddress ip, uint16_t port) final;
int connect(const char * host, uint16_t port) final;
int connect(const char * host, uint16_t port, int32_t timeout);
size_t write(uint8_t) final;
size_t write(const uint8_t * buf, size_t size) final;
size_t write(const char * str);
int available() final;
int read() final;
int read(uint8_t * buf, size_t size) final;
int peek() final;
void flush() final;
void stop() final;
uint8_t connected() final;
operator bool() final;

void setCACert(const char * rootCA);
void setCACertBundle(const uint8_t * bundle);
void setInsecure();
bool verify(const char * fingerprint, const char * domain_name);
};
9 changes: 9 additions & 0 deletions src/WebSockets.h
Original file line number Diff line number Diff line change
@@ -135,6 +135,7 @@
#define NETWORK_UNOWIFIR4 (7)
#define NETWORK_WIFI_NINA (8)
#define NETWORK_SAMD_SEED (9)
#define NETWORK_CUSTOM (10)

// max size of the WS Message Header
#define WEBSOCKETS_MAX_HEADER_SIZE (14)
@@ -286,6 +287,14 @@
#define WEBSOCKETS_NETWORK_CLASS WiFiClient
#define WEBSOCKETS_NETWORK_SERVER_CLASS WiFiServer

#elif(WEBSOCKETS_NETWORK_TYPE == NETWORK_CUSTOM)
#include <NetworkClient.h>
#include <WiFiServer.h>

#define SSL_AXTLS
#define WEBSOCKETS_NETWORK_CLASS NetworkClient
#define WEBSOCKETS_NETWORK_SSL_CLASS NetworkClient
#define WEBSOCKETS_NETWORK_SERVER_CLASS WiFiServer
#else
#error "no network type selected!"
#endif