Compare commits

..

3 Commits

Author SHA1 Message Date
stephb9959
17fe350d8c https://telecominfraproject.atlassian.net/browse/WIFI-10846
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-09-30 08:02:11 -07:00
stephb9959
73e4f0df94 https://telecominfraproject.atlassian.net/browse/WIFI-10846
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-09-29 22:53:48 -07:00
stephb9959
702d863e6b https://telecominfraproject.atlassian.net/browse/WIFI-10846
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
2022-09-29 22:46:24 -07:00
41 changed files with 455 additions and 632 deletions

View File

@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.13)
project(owgw VERSION 2.7.0)
project(owgw VERSION 2.7.1)
set(CMAKE_CXX_STANDARD 17)
@@ -79,10 +79,8 @@ add_executable( owgw
src/framework/KafkaTopics.h
src/framework/MicroService.h
src/framework/OpenWifiTypes.h
src/framework/MicroServiceErrorHandler.h
src/framework/orm.h
src/framework/StorageClass.h
src/framework/MicroServiceErrorHandler.h
src/RESTObjects/RESTAPI_SecurityObjects.h src/RESTObjects/RESTAPI_SecurityObjects.cpp
src/RESTObjects/RESTAPI_ProvObjects.cpp src/RESTObjects/RESTAPI_ProvObjects.h
src/RESTObjects/RESTAPI_GWobjects.h src/RESTObjects/RESTAPI_GWobjects.cpp
@@ -110,7 +108,7 @@ add_executable( owgw
src/Daemon.cpp src/Daemon.h
src/AP_WS_Server.cpp src/AP_WS_Server.h
src/StorageService.cpp src/StorageService.h
# src/DeviceRegistry.cpp src/DeviceRegistry.h
src/DeviceRegistry.cpp src/DeviceRegistry.h
src/CommandManager.cpp src/CommandManager.h
src/CentralConfig.cpp src/CentralConfig.h
src/FileUploader.cpp src/FileUploader.h
@@ -134,7 +132,7 @@ add_executable( owgw
src/AP_WS_Process_state.cpp
src/AP_WS_Process_healthcheck.cpp
src/AP_WS_Process_log.cpp
src/AP_WS_Process_crashlog.cpp src/AP_WS_Process_ping.cpp src/AP_WS_Process_cfgpending.cpp src/AP_WS_Process_recovery.cpp src/AP_WS_Process_deviceupdate.cpp src/AP_WS_Process_telemetry.cpp src/AP_WS_Process_venuebroadcast.cpp src/RADSECserver.h)
src/AP_WS_Process_crashlog.cpp src/AP_WS_Process_ping.cpp src/AP_WS_Process_cfgpending.cpp src/AP_WS_Process_recovery.cpp src/AP_WS_Process_deviceupdate.cpp src/AP_WS_Process_telemetry.cpp src/AP_WS_Process_venuebroadcast.cpp src/RADSECserver.h src/framework/MicroServiceErrorHandler.h)
if(NOT SMALL_BUILD)

View File

@@ -1,16 +1,16 @@
ARG DEBIAN_VERSION=11.4-slim
ARG ALPINE_VERSION=3.16.2
ARG POCO_VERSION=poco-tip-v1
ARG FMTLIB_VERSION=9.0.0
ARG CPPKAFKA_VERSION=tip-v1
ARG JSON_VALIDATOR_VERSION=2.1.0
FROM debian:$DEBIAN_VERSION AS build-base
FROM alpine:$ALPINE_VERSION AS build-base
RUN apt-get update && apt-get install --no-install-recommends -y \
RUN apk add --update --no-cache \
make cmake g++ git \
libpq-dev libmariadb-dev libmariadbclient-dev-compat \
librdkafka-dev libboost-all-dev libssl-dev \
zlib1g-dev nlohmann-json3-dev ca-certificates
unixodbc-dev postgresql-dev mariadb-dev \
librdkafka-dev boost-dev openssl-dev \
zlib-dev nlohmann-json ca-certificates
FROM build-base AS poco-build
@@ -90,21 +90,21 @@ WORKDIR /owgw/cmake-build
RUN cmake ..
RUN cmake --build . --config Release -j8
FROM debian:$DEBIAN_VERSION
FROM alpine:$ALPINE_VERSION
ENV OWGW_USER=owgw \
OWGW_ROOT=/owgw-data \
OWGW_CONFIG=/owgw-data
RUN useradd "$OWGW_USER"
RUN addgroup -S "$OWGW_USER" && \
adduser -S -G "$OWGW_USER" "$OWGW_USER"
RUN mkdir /openwifi
RUN mkdir -p "$OWGW_ROOT" "$OWGW_CONFIG" && \
chown "$OWGW_USER": "$OWGW_ROOT" "$OWGW_CONFIG"
RUN apt-get update && apt-get install --no-install-recommends -y \
librdkafka++1 gosu gettext ca-certificates bash jq curl wget \
libmariadb-dev-compat libpq5 unixodbc postgresql-client
RUN apk add --update --no-cache librdkafka su-exec gettext ca-certificates bash jq curl \
mariadb-connector-c libpq unixodbc postgresql-client
COPY readiness_check /readiness_check
COPY test_scripts/curl/cli /cli
@@ -114,14 +114,12 @@ COPY docker-entrypoint.sh /
COPY wait-for-postgres.sh /
COPY rtty_ui /dist/rtty_ui
RUN wget https://raw.githubusercontent.com/Telecominfraproject/wlan-cloud-ucentral-deploy/main/docker-compose/certs/restapi-ca.pem \
-O /usr/local/share/ca-certificates/restapi-ca-selfsigned.crt
-O /usr/local/share/ca-certificates/restapi-ca-selfsigned.pem
COPY --from=owgw-build /owgw/cmake-build/owgw /openwifi/owgw
COPY --from=cppkafka-build /cppkafka/cmake-build/src/lib /usr/local/lib/
COPY --from=poco-build /poco/cmake-build/lib /usr/local/lib
RUN ldconfig
EXPOSE 15002 16002 16003 17002 16102
ENTRYPOINT ["/docker-entrypoint.sh"]

2
build
View File

@@ -1 +1 @@
148
128

View File

@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
set -e
if [ "$SELFSIGNED_CERTS" = 'true' ]; then
@@ -38,12 +38,7 @@ if [[ "$TEMPLATE_CONFIG" = 'true' ]]; then
SYSTEM_URI_PRIVATE=${SYSTEM_URI_PRIVATE:-"https://localhost:17002"} \
SYSTEM_URI_PUBLIC=${SYSTEM_URI_PUBLIC:-"https://localhost:16002"} \
SYSTEM_URI_UI=${SYSTEM_URI_UI:-"http://localhost"} \
SECURITY_RESTAPI_DISABLE=${SECURITY_RESTAPI_DISABLE:-"false"} \
SIMULATORID=${SIMULATORID:-""} \
IPTOCOUNTRY_PROVIDER=${IPTOCOUNTRY_PROVIDER:-"ipinfo"} \
IPTOCOUNTRY_IPINFO_TOKEN=${IPTOCOUNTRY_IPINFO_TOKEN:-""} \
IPTOCOUNTRY_IPDATA_APIKEY=${IPTOCOUNTRY_IPDATA_APIKEY:-""} \
AUTOPROVISIONING_PROCESS=${AUTOPROVISIONING_PROCESS:-"prov,default"} \
RTTY_INTERNAL=${RTTY_INTERNAL:-"true"} \
RTTY_ENABLED=${RTTY_ENABLED:-"true"} \
RTTY_SERVER=${RTTY_SERVER:-"localhost"} \
@@ -52,10 +47,6 @@ if [[ "$TEMPLATE_CONFIG" = 'true' ]]; then
RTTY_TIMEOUT=${RTTY_TIMEOUT:-"60"} \
RTTY_VIEWPORT=${RTTY_VIEWPORT:-"5913"} \
RTTY_ASSETS=${RTTY_ASSETS:-"\$OWGW_ROOT/rtty_ui"} \
RADIUS_PROXY_ENABLE=${RADIUS_PROXY_ENABLE:-"false"} \
RADIUS_PROXY_ACCOUNTING_PORT=${RADIUS_PROXY_ACCOUNTING_PORT:-"1813"} \
RADIUS_PROXY_AUTHENTICATION_PORT=${RADIUS_PROXY_AUTHENTICATION_PORT:-"1812"} \
RADIUS_PROXY_COA_PORT=${RADIUS_PROXY_COA_PORT:-"3799"} \
KAFKA_ENABLE=${KAFKA_ENABLE:-"true"} \
KAFKA_BROKERLIST=${KAFKA_BROKERLIST:-"localhost:9092"} \
KAFKA_SSL_CA_LOCATION=${KAFKA_SSL_CA_LOCATION:-""} \
@@ -95,7 +86,7 @@ if [ "$1" = '/openwifi/owgw' -a "$(id -u)" = '0' ]; then
if [ "$RUN_CHOWN" = 'true' ]; then
chown -R "$OWGW_USER": "$OWGW_ROOT" "$OWGW_CONFIG"
fi
exec gosu "$OWGW_USER" "$@"
exec su-exec "$OWGW_USER" "$@"
fi
exec "$@"

View File

@@ -79,8 +79,7 @@ The following table lists the configurable parameters of the chart and their def
| persistence.size | string | Defines PV size | `'10Gi'` |
| public_env_variables | hash | Defines list of environment variables to be passed to the Gateway | |
| configProperties | hash | Configuration properties that should be passed to the application in `owgw.properties`. May be passed by key in set (i.e. `configProperties."rtty\.token"`) | |
| existingCertsSecret | string | Existing Kubernetes secret containing all required certificates and private keys for microservice operation. If set, certificates from `certs` key are ignored | `""` |
| certs | hash | Defines files (keys and certificates) that should be passed to the Gateway (PEM format is adviced to be used) (see `volumes.owgw` on where it is mounted). If `existingCertsSecret` is set, certificates passed this way will not be used. | |
| certs | hash | Defines files (keys and certificates) that should be passed to the Gateway (PEM format is adviced to be used) (see `volumes.owgw` on where it is mounted) | |
| certsCAs | hash | Defines files with CAs that should be passed to the Gateway (see `volumes.owgw` on where it is mounted) | |

View File

@@ -109,11 +109,6 @@ spec:
containerPort: {{ $portValue.targetPort }}
protocol: {{ $portValue.protocol }}
{{- end }}
{{- range $port, $portValue := .Values.services.radius.ports }}
- name: {{ $port }}
containerPort: {{ $portValue.targetPort }}
protocol: {{ $portValue.protocol }}
{{- end }}
volumeMounts:
{{- range .Values.volumes.owgw }}

View File

@@ -9,7 +9,7 @@ fullnameOverride: ""
images:
owgw:
repository: tip-tip-wlan-cloud-ucentral.jfrog.io/owgw
tag: v2.7.0
tag: master
pullPolicy: Always
# regcred:
# registry: tip-tip-wlan-cloud-ucentral.jfrog.io
@@ -46,21 +46,6 @@ services:
rttys-view:
servicePort: 5913
targetPort: 5913
radius:
type: ClusterIP
ports:
acc:
servicePort: 1813
targetPort: 1813
protocol: UDP
auth:
servicePort: 1812
targetPort: 1812
protocol: UDP
coa:
servicePort: 3799
targetPort: 3799
protocol: UDP
checks:
owgw:
@@ -112,7 +97,7 @@ volumes:
mountPath: /owgw-data/certs
volumeDefinition: |
secret:
secretName: {{ if .Values.existingCertsSecret }}{{ .Values.existingCertsSecret }}{{ else }}{{ include "owgw.fullname" . }}-certs{{ end }}
secretName: {{ include "owgw.fullname" . }}-certs
- name: certs-cas
mountPath: /owgw-data/certs/cas
volumeDefinition: |
@@ -138,7 +123,7 @@ resources: {}
# memory: 128Mi
securityContext:
fsGroup: 1000
fsGroup: 101
# Usage of unsafe sysctls requires multiple things:
# - allow these unsafe sysctls on kubelet level (by adding --allowed-unsafe-sysctls flag)
# - enabling addition of PodSecurityContext setting podSecurityPolicy.enabled to "true" below
@@ -246,11 +231,6 @@ configProperties:
rtty.timeout: 60
rtty.viewport: 5913
rtty.assets: $OWGW_ROOT/rtty_ui
# RADIUS proxy
radius.proxy.enable: "true"
radius.proxy.accounting.port: 1813
radius.proxy.authentication.port: 1812
radius.proxy.coa.port: 3799
# ALB
alb.enable: "true"
alb.port: 16102
@@ -291,12 +271,11 @@ configProperties:
openwifi.system.debug: "true"
openwifi.system.uri.private: https://localhost:17002
openwifi.system.uri.public: https://localhost:16002
openwifi.system.uri.ui: https://localhost
openwifi.system.commandchannel: /tmp/app_owgw
# Logging
logging.type: console
logging.path: $OWGW_ROOT/logs
logging.level: information
logging.level: debug
# Archiving
archiver.enabled: "true"
archiver.schedule: 03:00
@@ -331,22 +310,166 @@ configProperties:
storage.type.mysql.username: stephb
storage.type.mysql.password: snoopy99
# NOTE: List of required certificates may be found in "certs" key. Alternative way to pass required certificates is to create external secret with all required certificates and set secret name in "existingCertsSecret" key. Details may be found in https://github.com/Telecominfraproject/wlan-cloud-ucentral-deploy/tree/main/chart#tldr
existingCertsSecret: ""
certs:
clientcas.pem: ""
issuer.pem: ""
restapi-ca.pem: ""
restapi-cert.pem: ""
restapi-key.pem: ""
root.pem: ""
websocket-cert.pem: ""
websocket-key.pem: ""
clientcas.pem: |
-----BEGIN CERTIFICATE-----
MIIEnDCCA4SgAwIBAgIUVpyCUx1MUeUwxg+7I1BvGFTz7HkwDQYJKoZIhvcNAQEL
BQAwaTELMAkGA1UEBhMCVVMxJDAiBgNVBAoTG1RlbGVjb20gSW5mcmEgUHJvamVj
dCwgSW5jLjEMMAoGA1UECxMDVElQMSYwJAYDVQQDEx1UZWxlY29tIEluZnJhIFBy
b2plY3QgUm9vdCBDQTAeFw0yMTA0MTMyMjUxMjZaFw0yNjA0MTMyMjM4NDZaMGwx
CzAJBgNVBAYTAlVTMSQwIgYDVQQKExtUZWxlY29tIEluZnJhIFByb2plY3QsIElu
Yy4xDDAKBgNVBAsTA1RJUDEpMCcGA1UEAxMgVGVsZWNvbSBJbmZyYSBQcm9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0P6HjySBHgTTU7/tYS/OZr1jI6MPbG
L+/DtiR5fDVMNdBSGU89UNTi0wHY9+RFuNlIuvZC+x/swF0V9R5mN+ywquTPtDLA
5IOM7ItsRmen6u3qu+JXros54e4juQ==
-----END CERTIFICATE-----
# websocket-cert.pem: ""
# websocket-key.pem: ""
certsCAs:
issuer.pem: ""
root.pem: ""
issuer.pem: |
-----BEGIN CERTIFICATE-----
MIIEnDCCA4SgAwIBAgIUVpyCUx1MUeUwxg+7I1BvGFTz7HkwDQYJKoZIhvcNAQEL
BQAwaTELMAkGA1UEBhMCVVMxJDAiBgNVBAoTG1RlbGVjb20gSW5mcmEgUHJvamVj
dCwgSW5jLjEMMAoGA1UECxMDVElQMSYwJAYDVQQDEx1UZWxlY29tIEluZnJhIFBy
b2plY3QgUm9vdCBDQTAeFw0yMTA0MTMyMjUxMjZaFw0yNjA0MTMyMjM4NDZaMGwx
CzAJBgNVBAYTAlVTMSQwIgYDVQQKExtUZWxlY29tIEluZnJhIFByb2plY3QsIElu
Yy4xDDAKBgNVBAsTA1RJUDEpMCcGA1UEAxMgVGVsZWNvbSBJbmZyYSBQcm9qZWN0
IElzc3VpbmcgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDtKBrq
qd2aKVSk25KfL5xHu8X7/8rJrz3IvyPuVKWhk/N1zabot3suBcGaYNKjnRHxg78R
yKwKzajKYWtiQFqztu24g16LQeAnoUxZnF6a0z3JkkRPsz14A2y8TUhdEe1tx+UU
4VGsk3n+FMmOQHL+79FO57zQC1LwylgfLSltrI6mF3jowVUQvnwzKhUzT87AJ6EO
ndK/q0T/Bgi+aI39zfVOjJjsTJwghvrmYW3iarP1THSKxeib2s02bZKrvvHa5HL4
UI8+LvREpVZl4mzt1z6Nl344Y6f+UeJlYa/Ci0jJqaXJmyVnUbAz+c0i5JfwAVn3
YQzfC4eLnZCmdF8zAgMBAAGjggE3MIIBMzAPBgNVHRMBAf8EBTADAQH/MB0GA1Ud
Dg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lVTMSQwIgYDVQQKExtUZWxlY29tIEluZnJhIFByb2plY3QsIElu
Yy4xDDAKBgNVBAsTA1RJUDEmMCQGA1UEAxMdVGVsZWNvbSBJbmZyYSBQcm9qZWN0
IFJvb3QgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDIGCibwf5u
AAwZ+1H8U0e3u2V+0d2gSctucoK86XwUmfe1V2a/qlCYZd29r80IuN1IIeB0naIm
KnK/MzXW87clF6tFd1+HzEvmlY/W4KyIXalVCTEzirFSvBEG2oZpM0yC3AefytAO
aOpA00LaM3xTfTqMKIRhJBuLy0I4ANUVG6ixVebbGuc78IodleqiLoWy2Q9QHyEO
t/7hZndJhiVogh0PveRhho45EbsACu7ymDY+JhlIleevqwlE3iQoq0YcmYADHno6
Eq8vcwLpZFxihupUafkd1T3WJYQAJf9coCjBu2qIhNgrcrGD8R9fGswwNRzMRMpX
720+GjcDW3bJAgMBAAGjQjBAMA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYEFAJG
lmB5sVP2qfL3xZ8hQOTpkQH6MA4GA1UdDwEB/wQEAwIBhjANBgkqhkiG9w0BAQsF
AAOCAQEAVjl9dm4epG9NUYnagT9sg7scVQEPfz3Lt6w1NXJXgD8mAUlK0jXmEyvM
dCPD4514n+8+lM7US8fh+nxc7jO//LwK17Wm9FblgjNFR7+anv0Q99T9fP19DLlF
PSNHL2emogy1bl1lLTAoj8nxg2wVKPDSHBGviQ5LR9fsWUIJDv9Bs5k0qWugWYSj
19S6qnHeskRDB8MqRLhKMG82oDVLerSnhD0P6HjySBHgTTU7/tYS/OZr1jI6MPbG
L+/DtiR5fDVMNdBSGU89UNTi0wHY9+RFuNlIuvZC+x/swF0V9R5mN+ywquTPtDLA
5IOM7ItsRmen6u3qu+JXros54e4juQ==
-----END CERTIFICATE-----
# PostgreSQL (https://github.com/bitnami/charts/tree/master/bitnami/postgresql)
postgresql:

View File

@@ -65,7 +65,6 @@ openwifi.system.debug = true
openwifi.system.uri.private = https://localhost:17002
openwifi.system.uri.public = https://ucentral.dpaas.arilia.com:16002
openwifi.system.uri.ui = https://ucentral-ui.arilia.com
openwifi.security.restapi.disable = false
openwifi.system.commandchannel = /tmp/app.ucentralgw
#
@@ -178,4 +177,4 @@ archiver.db.3.keep = 7
########################################################################
logging.type = file
logging.path = $OWGW_ROOT/logs
logging.level = information
logging.level = debug

View File

@@ -52,8 +52,8 @@ openwifi.fileuploader.host.0.cert = ${FILEUPLOADER_HOST_CERT}
openwifi.fileuploader.host.0.key = ${FILEUPLOADER_HOST_KEY}
openwifi.fileuploader.host.0.key.password = ${FILEUPLOADER_HOST_KEY_PASSWORD}
openwifi.fileuploader.path = ${FILEUPLOADER_PATH}
openwifi.fileuploader.maxsize = 10000
openwifi.fileuploader.uri = ${FILEUPLOADER_URI}
openwifi.fileuploader.maxsize = 10000
#
# Generic section that all microservices must have
@@ -65,7 +65,6 @@ openwifi.system.debug = true
openwifi.system.uri.private = ${SYSTEM_URI_PRIVATE}
openwifi.system.uri.public = ${SYSTEM_URI_PUBLIC}
openwifi.system.uri.ui = ${SYSTEM_URI_UI}
openwifi.security.restapi.disable = ${SECURITY_RESTAPI_DISABLE}
openwifi.system.commandchannel = /tmp/app.ucentralgw
#
@@ -76,13 +75,8 @@ openwifi.devicetypes.0 = AP:linksys_ea8300,edgecore_eap101,linksys_e8450-ubi
openwifi.devicetypes.1 = SWITCH:edgecore_ecs4100-12ph
openwifi.devicetypes.2 = IOT:esp32
oui.download.uri = https://standards-oui.ieee.org/oui/oui.txt
firmware.autoupdate.policy.default = auto
simulatorid = ${SIMULATORID}
iptocountry.default = US
iptocountry.provider = ${IPTOCOUNTRY_PROVIDER}
iptocountry.ipinfo.token = ${IPTOCOUNTRY_IPINFO_TOKEN}
iptocountry.ipdata.apikey = ${IPTOCOUNTRY_IPDATA_APIKEY}
autoprovisioning.process = ${AUTOPROVISIONING_PROCESS}
#
# rtty
@@ -96,12 +90,6 @@ rtty.timeout = ${RTTY_TIMEOUT}
rtty.viewport = ${RTTY_VIEWPORT}
rtty.assets = ${RTTY_ASSETS}
### RADIUS proxy config
radius.proxy.enable = ${RADIUS_PROXY_ENABLE}
radius.proxy.accounting.port = ${RADIUS_PROXY_ACCOUNTING_PORT}
radius.proxy.authentication.port = ${RADIUS_PROXY_AUTHENTICATION_PORT}
radius.proxy.coa.port = ${RADIUS_PROXY_COA_PORT}
#############################
# Generic information for all micro services
#############################
@@ -120,7 +108,6 @@ openwifi.kafka.enable = ${KAFKA_ENABLE}
openwifi.kafka.brokerlist = ${KAFKA_BROKERLIST}
openwifi.kafka.auto.commit = false
openwifi.kafka.queue.buffering.max.ms = 50
openwifi.kafka.ssl.ca.location = ${KAFKA_SSL_CA_LOCATION}
openwifi.kafka.ssl.certificate.location = ${KAFKA_SSL_CERTIFICATE_LOCATION}
openwifi.kafka.ssl.key.location = ${KAFKA_SSL_KEY_LOCATION}
@@ -174,4 +161,4 @@ archiver.db.3.keep = 7
########################################################################
logging.type = console
logging.path = $OWGW_ROOT/logs
logging.level = information
logging.level = debug

View File

@@ -62,7 +62,6 @@ namespace OpenWifi {
*WS_, Poco::NObserver<AP_WS_Connection, Poco::Net::ErrorNotification>(
*this, &AP_WS_Connection::OnSocketError));
Registered_ = true;
Valid_ = true;
}
class ThreadedCounter {
@@ -90,9 +89,6 @@ namespace OpenWifi {
if(DeviceValidated_)
return true;
if(!Valid_)
return false;
try {
auto SockImpl = dynamic_cast<Poco::Net::WebSocketImpl *>(WS_->impl());
auto SS = dynamic_cast<Poco::Net::SecureStreamSocketImpl*>(SockImpl->streamSocketImpl());
@@ -193,6 +189,125 @@ namespace OpenWifi {
return false;
}
void AP_WS_Connection::CompleteStartup() {
std::lock_guard Guard(Mutex_);
auto TC = ThreadedCounter(Threaded_,ConcurrentStartingDevices_);
try {
auto SockImpl = dynamic_cast<Poco::Net::WebSocketImpl *>(WS_->impl());
auto SS = dynamic_cast<Poco::Net::SecureStreamSocketImpl*>(SockImpl->streamSocketImpl());
/* while (true) {
auto V = SS->completeHandshake();
if (V == 1)
break;
}
*/
PeerAddress_ = SS->peerAddress().host();
CId_ = Utils::FormatIPv6(SS->peerAddress().toString());
State_.started = OpenWifi::Now();
if (!SS->secure()) {
poco_warning(Logger_,fmt::format("CONNECTION({}): Session={} Connection is NOT secure. Device is not allowed.", CId_, State_.sessionId ));
return EndConnection();
}
poco_debug(Logger_,fmt::format("CONNECTION({}): Session={} Connection is secure.", CId_, State_.sessionId ));
if (!SS->havePeerCertificate()) {
State_.VerifiedCertificate = GWObjects::NO_CERTIFICATE;
poco_warning(Logger_,fmt::format("CONNECTION({}): Session={} No certificates available..", CId_, State_.sessionId ));
return EndConnection();
}
Poco::Crypto::X509Certificate PeerCert(SS->peerCertificate());
if (!AP_WS_Server()->ValidateCertificate(CId_, PeerCert)) {
State_.VerifiedCertificate = GWObjects::NO_CERTIFICATE;
poco_warning(Logger_, fmt::format("CONNECTION({}): Session={} Device certificate is not valid. Device is not allowed.",
CId_, State_.sessionId ));
return EndConnection();
}
CN_ = Poco::trim(Poco::toLower(PeerCert.commonName()));
State_.VerifiedCertificate = GWObjects::VALID_CERTIFICATE;
poco_debug(Logger_,
fmt::format("CONNECTION({}): Session={} Valid certificate: CN={}", CId_, State_.sessionId , CN_));
if (AP_WS_Server::IsSim(CN_) && !AP_WS_Server()->IsSimEnabled()) {
poco_warning(
Logger_,
fmt::format("CONNECTION({}): Session={} Sim Device {} is not allowed. Disconnecting.",
CId_, State_.sessionId , CN_));
return EndConnection();
}
if (!CN_.empty() && StorageService()->IsBlackListed(SerialNumber_)) {
poco_warning(
Logger_,
fmt::format("CONNECTION({}): Session={} Device {} is black listed. Disconnecting.",
CId_, State_.sessionId , CN_));
return EndConnection();
}
SerialNumber_ = CN_;
SerialNumberInt_ = Utils::SerialNumberToInt(SerialNumber_);
WS_->setMaxPayloadSize(BufSize);
auto TS = Poco::Timespan(360, 0);
WS_->setReceiveTimeout(TS);
WS_->setNoDelay(true);
WS_->setKeepAlive(true);
WS_->setBlocking(false);
Reactor_.addEventHandler(
*WS_, Poco::NObserver<AP_WS_Connection, Poco::Net::ReadableNotification>(
*this, &AP_WS_Connection::OnSocketReadable));
Reactor_.addEventHandler(
*WS_, Poco::NObserver<AP_WS_Connection, Poco::Net::ShutdownNotification>(
*this, &AP_WS_Connection::OnSocketShutdown));
Reactor_.addEventHandler(
*WS_, Poco::NObserver<AP_WS_Connection, Poco::Net::ErrorNotification>(
*this, &AP_WS_Connection::OnSocketError));
Registered_ = true;
poco_debug(Logger_, fmt::format("CONNECTION({}): Session={} CN={} Completed. (t={})", CId_, State_.sessionId , CN_, ConcurrentStartingDevices_));
return;
} catch (const Poco::Net::CertificateValidationException &E) {
poco_error(Logger_,fmt::format("CONNECTION({}): Session:{} Poco::CertificateValidationException Certificate Validation failed during connection. Device will have to retry.",
CId_, State_.sessionId ));
Logger_.log(E);
} catch (const Poco::Net::WebSocketException &E) {
poco_error(Logger_,fmt::format("CONNECTION({}): Session:{} Poco::WebSocketException WebSocket error during connection. Device will have to retry.",
CId_, State_.sessionId ));
Logger_.log(E);
} catch (const Poco::Net::ConnectionAbortedException &E) {
poco_error(Logger_,fmt::format("CONNECTION({}):Session:{} Poco::ConnectionAbortedException Connection was aborted during connection. Device will have to retry.",
CId_, State_.sessionId ));
Logger_.log(E);
} catch (const Poco::Net::ConnectionResetException &E) {
poco_error(Logger_,fmt::format("CONNECTION({}): Session:{} Poco::ConnectionResetException Connection was reset during connection. Device will have to retry.",
CId_, State_.sessionId ));
Logger_.log(E);
} catch (const Poco::Net::InvalidCertificateException &E) {
poco_error(Logger_,fmt::format(
"CONNECTION({}): Session:{} Poco::InvalidCertificateException Invalid certificate. Device will have to retry.",
CId_, State_.sessionId ));
Logger_.log(E);
} catch (const Poco::Net::SSLException &E) {
poco_error(Logger_,fmt::format("CONNECTION({}): Session:{} Poco::SSLException SSL Exception during connection. Device will have to retry.",
CId_, State_.sessionId ));
Logger_.log(E);
} catch (const Poco::Exception &E) {
poco_error(Logger_,fmt::format("CONNECTION({}): Session:{} Poco::Exception caught during device connection. Device will have to retry.",
CId_, State_.sessionId ));
Logger_.log(E);
} catch (...) {
poco_error(Logger_,fmt::format("CONNECTION({}): Session:{} Exception caught during device connection. Device will have to retry. Unsecure connect denied.",
CId_, State_.sessionId ));
}
return EndConnection();
}
static void NotifyKafkaDisconnect(const std::string & SerialNumber) {
try {
Poco::JSON::Object Disconnect;
@@ -209,39 +324,36 @@ namespace OpenWifi {
}
AP_WS_Connection::~AP_WS_Connection() {
std::cout << "Deleting session=" << State_.sessionId << std::endl;
Valid_=false;
EndConnection();
if(!Dead_)
EndConnection();
}
void AP_WS_Connection::EndConnection() {
Valid_=false;
if(!Dead_.test_and_set()) {
Dead_=true;
poco_information(Logger_,fmt::format("CONNECTION-CLOSING({}): Session={} Serial={}.", CId_, State_.sessionId, SerialNumber_));
auto SessionDeleted = DeviceRegistry()->EndSession(State_.sessionId, SerialNumberInt_);
if (Registered_) {
Registered_ = false;
Reactor_.removeEventHandler(
*WS_, Poco::NObserver<AP_WS_Connection, Poco::Net::ReadableNotification>(
*this, &AP_WS_Connection::OnSocketReadable));
Reactor_.removeEventHandler(
*WS_, Poco::NObserver<AP_WS_Connection, Poco::Net::ShutdownNotification>(
*this, &AP_WS_Connection::OnSocketShutdown));
Reactor_.removeEventHandler(
*WS_, Poco::NObserver<AP_WS_Connection, Poco::Net::ErrorNotification>(
*this, &AP_WS_Connection::OnSocketError));
}
WS_->close();
if (KafkaManager()->Enabled() && !SerialNumber_.empty()) {
std::string s(SerialNumber_);
std::thread t([s]() { NotifyKafkaDisconnect(s); });
t.detach();
}
auto SessionDeleted = AP_WS_Server()->EndSession(State_.sessionId, SerialNumberInt_);
if (SessionDeleted)
WebSocketClientNotificationDeviceDisconnected(SerialNumber_);
if (Registered_) {
Reactor_.removeEventHandler(
*WS_, Poco::NObserver<AP_WS_Connection, Poco::Net::ReadableNotification>(
*this, &AP_WS_Connection::OnSocketReadable));
Reactor_.removeEventHandler(
*WS_, Poco::NObserver<AP_WS_Connection, Poco::Net::ShutdownNotification>(
*this, &AP_WS_Connection::OnSocketShutdown));
Reactor_.removeEventHandler(
*WS_, Poco::NObserver<AP_WS_Connection, Poco::Net::ErrorNotification>(
*this, &AP_WS_Connection::OnSocketError));
}
WS_->close();
if (KafkaManager()->Enabled() && !SerialNumber_.empty()) {
std::string s(SerialNumber_);
std::thread t([s]() { NotifyKafkaDisconnect(s); });
t.detach();
}
if(SessionDeleted)
WebSocketClientNotificationDeviceDisconnected(SerialNumber_);
AP_WS_Server()->DeleteConnection(State_.sessionId);
}
bool AP_WS_Connection::LookForUpgrade(const uint64_t UUID, uint64_t & UpgradedUUID) {
@@ -535,19 +647,19 @@ namespace OpenWifi {
}
void AP_WS_Connection::OnSocketShutdown([[maybe_unused]] const Poco::AutoPtr<Poco::Net::ShutdownNotification> &pNf) {
std::lock_guard Guard(Mutex_);
poco_trace(Logger_, fmt::format("SOCKET-SHUTDOWN({}): Closing.", CId_));
return EndConnection();
}
void AP_WS_Connection::OnSocketError([[maybe_unused]] const Poco::AutoPtr<Poco::Net::ErrorNotification> &pNf) {
std::lock_guard Guard(Mutex_);
poco_trace(Logger_, fmt::format("SOCKET-ERROR({}): Closing.", CId_));
return EndConnection();
}
void AP_WS_Connection::OnSocketReadable([[maybe_unused]] const Poco::AutoPtr<Poco::Net::ReadableNotification> &pNf) {
if(!Valid_)
return;
std::lock_guard Guard(Mutex_);
if(!AP_WS_Server()->Running())
return EndConnection();

View File

@@ -5,8 +5,6 @@
#pragma once
#include <string>
#include <shared_mutex>
#include "Poco/Net/SocketReactor.h"
#include "Poco/Net/StreamSocket.h"
#include "Poco/JSON/Object.h"
@@ -14,6 +12,7 @@
#include "Poco/Logger.h"
#include "Poco/Net/WebSocket.h"
#include "DeviceRegistry.h"
#include "RESTObjects/RESTAPI_GWobjects.h"
@@ -84,10 +83,9 @@ namespace OpenWifi {
}
friend class DeviceRegistry;
friend class AP_WS_Server;
private:
// std::recursive_mutex LocalMutex_;
std::recursive_mutex Mutex_;
std::shared_mutex TelemetryMutex_;
Poco::Logger &Logger_;
Poco::Net::SocketReactor &Reactor_;
@@ -114,12 +112,12 @@ namespace OpenWifi {
std::chrono::time_point<std::chrono::high_resolution_clock> ConnectionStart_ = std::chrono::high_resolution_clock::now();
std::chrono::duration<double, std::milli> ConnectionCompletionTime_{0.0};
bool Threaded_=false;
std::atomic_flag Dead_=false;
std::atomic_bool Dead_=false;
std::atomic_bool DeviceValidated_=false;
std::atomic_bool Valid_=false;
static inline std::atomic_uint64_t ConcurrentStartingDevices_=0;
void CompleteStartup();
bool StartTelemetry(std::uint64_t RPCID);
bool StopTelemetry(std::uint64_t RPCID);
void UpdateCounts();

View File

@@ -3,8 +3,6 @@
//
#include "AP_WS_Connection.h"
#include "fmt/format.h"
#include "framework/ow_constants.h"
namespace OpenWifi {
void AP_WS_Connection::Process_cfgpending(Poco::JSON::Object::Ptr ParamsObj) {

View File

@@ -8,7 +8,6 @@
#include "FindCountry.h"
#include "framework/WebSocketClientNotifications.h"
#include "Daemon.h"
#include "CentralConfig.h"
#include "CommandManager.h"
@@ -20,17 +19,15 @@ void AP_WS_Connection::Process_connect(Poco::JSON::Object::Ptr ParamsObj, const
ParamsObj->has(uCentralProtocol::CAPABILITIES)) {
uint64_t UUID = ParamsObj->get(uCentralProtocol::UUID);
auto Firmware = ParamsObj->get(uCentralProtocol::FIRMWARE).toString();
auto CapabilitiesString = ParamsObj->get(uCentralProtocol::CAPABILITIES).toString();
Config::Capabilities Caps(CapabilitiesString);
Compatible_ = Caps.Compatible();
auto Capabilities = ParamsObj->get(uCentralProtocol::CAPABILITIES).toString();
//// change this
SerialNumber_ = Serial;
SerialNumberInt_ = Utils::SerialNumberToInt(SerialNumber_);
CommandManager()->ClearQueue(SerialNumberInt_);
AP_WS_Server()->SetSessionDetails(State_.sessionId,SerialNumberInt_);
DeviceRegistry()->SetSessionDetails(State_.sessionId,SerialNumberInt_);
State_.UUID = UUID;
State_.Firmware = Firmware;
State_.PendingUUID = 0;
@@ -46,10 +43,10 @@ void AP_WS_Connection::Process_connect(Poco::JSON::Object::Ptr ParamsObj, const
GWObjects::Device DeviceInfo;
auto DeviceExists = StorageService()->GetDevice(SerialNumber_,DeviceInfo);
if (Daemon()->AutoProvisioning() && !DeviceExists) {
StorageService()->CreateDefaultDevice(SerialNumber_, CapabilitiesString, Firmware,
StorageService()->CreateDefaultDevice(SerialNumber_, Capabilities, Firmware,
Compatible_, PeerAddress_);
} else if (DeviceExists) {
StorageService()->UpdateDeviceCapabilities(SerialNumber_, CapabilitiesString,
StorageService()->UpdateDeviceCapabilities(SerialNumber_, Capabilities,
Compatible_);
bool Updated = false;
if(!Firmware.empty() && Firmware!=DeviceInfo.Firmware) {
@@ -108,8 +105,6 @@ void AP_WS_Connection::Process_connect(Poco::JSON::Object::Ptr ParamsObj, const
WebSocketClientNotificationDeviceConnected(SerialNumber_);
// std::cout << "Serial: " << SerialNumber_ << "Session: " << State_.sessionId << std::endl;
if (KafkaManager()->Enabled()) {
Poco::JSON::Stringifier Stringify;
ParamsObj->set(uCentralProtocol::CONNECTIONIP, CId_);

View File

@@ -3,8 +3,6 @@
//
#include "AP_WS_Connection.h"
#include "fmt/format.h"
#include "framework/ow_constants.h"
namespace OpenWifi {
void AP_WS_Connection::Process_ping(Poco::JSON::Object::Ptr ParamsObj) {

View File

@@ -11,10 +11,8 @@
#include "Poco/Net/Context.h"
#include "AP_WS_Server.h"
#include "AP_WS_Connection.h"
#include "ConfigurationCache.h"
#include "TelemetryStream.h"
#include "framework/WebSocketClientNotifications.h"
namespace OpenWifi {
@@ -145,65 +143,14 @@ namespace OpenWifi {
SimulatorEnabled_ = !SimulatorId_.empty();
Utils::SetThreadName(ReactorThread_,"dev:react:head");
GarbageCollectorCallback_ = std::make_unique<Poco::TimerCallback<AP_WS_Server>>(*this,&AP_WS_Server::onGarbageCollecting);
Timer_.setStartInterval(10 * 1000);
Timer_.setPeriodicInterval(5 * 1000); // every minute
Timer_.start(*GarbageCollectorCallback_, MicroService::instance().TimerPool());
Running_ = true;
return 0;
}
void AP_WS_Server::onGarbageCollecting([[maybe_unused]] Poco::Timer &timer) {
std::lock_guard Lock(LocalMutex_);
if(Garbage_.size()>0) {
std::cout << "Removing " << Garbage_.size() << " old connections." << std::endl;
Garbage_.clear();
}
static std::uint64_t last_log = OpenWifi::Now();
NumberOfConnectedDevices_ = 0;
NumberOfConnectingDevices_ = 0;
AverageDeviceConnectionTime_ = 0;
std::uint64_t total_connected_time=0;
auto now = OpenWifi::Now();
for (auto connection=SerialNumbers_.begin(); connection!=SerialNumbers_.end();) {
if(connection->second.second== nullptr) {
connection++;
continue;
}
if (connection->second.second->State_.Connected) {
NumberOfConnectedDevices_++;
total_connected_time += (now - connection->second.second->State_.started);
connection++;
} else {
NumberOfConnectingDevices_++;
connection++;
}
}
AverageDeviceConnectionTime_ = (NumberOfConnectedDevices_!=0) ? total_connected_time/NumberOfConnectedDevices_ : 0;
if((now-last_log)>120) {
last_log = now;
poco_information(Logger(),
fmt::format("Active AP connections: {} Connecting: {} Average connection time: {} seconds",
NumberOfConnectedDevices_, NumberOfConnectingDevices_, AverageDeviceConnectionTime_));
}
WebSocketClientNotificationNumberOfConnections(NumberOfConnectedDevices_,
AverageDeviceConnectionTime_,
NumberOfConnectingDevices_);
}
void AP_WS_Server::Stop() {
poco_information(Logger(),"Stopping...");
Running_ = false;
Timer_.stop();
for(auto &server:WebServers_) {
server->stopAll();
}
@@ -213,198 +160,4 @@ namespace OpenWifi {
poco_information(Logger(),"Stopped...");
}
bool AP_WS_Server::GetStatistics(std::uint64_t SerialNumber, std::string &Statistics) const {
std::lock_guard Lock(LocalMutex_);
auto Device = SerialNumbers_.find(SerialNumber);
if(Device == SerialNumbers_.end() || Device->second.second==nullptr)
return false;
Statistics = Device->second.second->LastStats_;
return true;
}
bool AP_WS_Server::GetState(uint64_t SerialNumber, GWObjects::ConnectionState & State) const {
std::lock_guard Lock(LocalMutex_);
auto Device = SerialNumbers_.find(SerialNumber);
if(Device == SerialNumbers_.end() || Device->second.second==nullptr)
return false;
State = Device->second.second->State_;
return true;
}
bool AP_WS_Server::GetHealthcheck(uint64_t SerialNumber, GWObjects::HealthCheck & CheckData) const {
std::lock_guard Lock(LocalMutex_);
auto Device = SerialNumbers_.find(SerialNumber);
if(Device == SerialNumbers_.end() || Device->second.second==nullptr)
return false;
CheckData = Device->second.second->LastHealthcheck_;
return true;
}
void AP_WS_Server::SetSessionDetails(std::uint64_t connection_id, uint64_t SerialNumber) {
std::lock_guard Lock(LocalMutex_);
auto Conn = Sessions_.find(connection_id);
if(Conn == end(Sessions_))
return;
auto CurrentSerialNumber = SerialNumbers_.find(SerialNumber);
if( (CurrentSerialNumber==SerialNumbers_.end()) ||
(CurrentSerialNumber->second.first<connection_id)) {
SerialNumbers_[SerialNumber] = std::make_pair(connection_id, Conn->second.first);
return;
}
}
bool AP_WS_Server::EndSession(std::uint64_t session_id, std::uint64_t serial_number) {
std::unique_lock G(LocalMutex_);
auto Session = Sessions_.find(session_id);
if(Session==end(Sessions_))
return false;
Garbage_.push_back(Session->second.first);
auto Device = SerialNumbers_.find(serial_number);
if (Device == end(SerialNumbers_)) {
Sessions_.erase(Session);
return false;
}
if(Device->second.first==session_id) {
Sessions_.erase(Session);
SerialNumbers_.erase(Device);
return true;
}
Sessions_.erase(Session);
return false;
}
bool AP_WS_Server::Connected(uint64_t SerialNumber) const {
std::lock_guard Lock(LocalMutex_);
auto Device = SerialNumbers_.find(SerialNumber);
if(Device==end(SerialNumbers_) || Device->second.second== nullptr)
return false;
return Device->second.second->State_.Connected;
}
bool AP_WS_Server::SendFrame(uint64_t SerialNumber, const std::string & Payload) const {
std::lock_guard Lock(LocalMutex_);
auto Device = SerialNumbers_.find(SerialNumber);
if(Device==SerialNumbers_.end() || Device->second.second== nullptr)
return false;
try {
// std::cout << "Device connection pointer: " << (std::uint64_t) Device->second.second << std::endl;
return Device->second.second->Send(Payload);
} catch (...) {
poco_debug(Logger(),fmt::format(": SendFrame: Could not send data to device '{}'", Utils::IntToSerialNumber(SerialNumber)));
}
return false;
}
void AP_WS_Server::StopWebSocketTelemetry(std::uint64_t RPCID, uint64_t SerialNumber) {
std::lock_guard Lock(LocalMutex_);
auto Device = SerialNumbers_.find(SerialNumber);
if(Device==end(SerialNumbers_) || Device->second.second==nullptr)
return;
Device->second.second->StopWebSocketTelemetry(RPCID);
}
void AP_WS_Server::SetWebSocketTelemetryReporting(std::uint64_t RPCID, uint64_t SerialNumber, uint64_t Interval, uint64_t Lifetime) {
std::lock_guard Lock(LocalMutex_);
auto Device = SerialNumbers_.find(SerialNumber);
if(Device==end(SerialNumbers_) || Device->second.second==nullptr)
return;
Device->second.second->SetWebSocketTelemetryReporting(RPCID, Interval, Lifetime);
}
void AP_WS_Server::SetKafkaTelemetryReporting(std::uint64_t RPCID, uint64_t SerialNumber, uint64_t Interval, uint64_t Lifetime) {
std::lock_guard Lock(LocalMutex_);
auto Device = SerialNumbers_.find(SerialNumber);
if(Device==end(SerialNumbers_) || Device->second.second== nullptr)
return;
Device->second.second->SetKafkaTelemetryReporting(RPCID, Interval, Lifetime);
}
void AP_WS_Server::StopKafkaTelemetry(std::uint64_t RPCID, uint64_t SerialNumber) {
std::lock_guard Lock(LocalMutex_);
auto Device = SerialNumbers_.find(SerialNumber);
if(Device==end(SerialNumbers_) || Device->second.second== nullptr)
return;
Device->second.second->StopKafkaTelemetry(RPCID);
}
void AP_WS_Server::GetTelemetryParameters(uint64_t SerialNumber , bool & TelemetryRunning,
uint64_t & TelemetryInterval,
uint64_t & TelemetryWebSocketTimer,
uint64_t & TelemetryKafkaTimer,
uint64_t & TelemetryWebSocketCount,
uint64_t & TelemetryKafkaCount,
uint64_t & TelemetryWebSocketPackets,
uint64_t & TelemetryKafkaPackets) {
std::lock_guard Lock(LocalMutex_);
auto Device = SerialNumbers_.find(SerialNumber);
if(Device==end(SerialNumbers_)|| Device->second.second== nullptr)
return;
Device->second.second->GetTelemetryParameters(TelemetryRunning,
TelemetryInterval,
TelemetryWebSocketTimer,
TelemetryKafkaTimer,
TelemetryWebSocketCount,
TelemetryKafkaCount,
TelemetryWebSocketPackets,
TelemetryKafkaPackets);
}
bool AP_WS_Server::SendRadiusAccountingData(const std::string & SerialNumber, const unsigned char * buffer, std::size_t size) {
std::lock_guard Lock(LocalMutex_);
auto Device = SerialNumbers_.find(Utils::SerialNumberToInt(SerialNumber));
if(Device==SerialNumbers_.end() || Device->second.second== nullptr)
return false;
try {
return Device->second.second->SendRadiusAccountingData(buffer,size);
} catch (...) {
poco_debug(Logger(),fmt::format(": SendRadiusAuthenticationData: Could not send data to device '{}'", SerialNumber));
}
return false;
}
bool AP_WS_Server::SendRadiusAuthenticationData(const std::string & SerialNumber, const unsigned char * buffer, std::size_t size) {
std::lock_guard Lock(LocalMutex_);
auto Device = SerialNumbers_.find(Utils::SerialNumberToInt(SerialNumber));
if(Device==SerialNumbers_.end() || Device->second.second== nullptr)
return false;
try {
return Device->second.second->SendRadiusAuthenticationData(buffer,size);
} catch (...) {
poco_debug(Logger(),fmt::format(": SendRadiusAuthenticationData: Could not send data to device '{}'", SerialNumber));
}
return false;
}
bool AP_WS_Server::SendRadiusCoAData(const std::string & SerialNumber, const unsigned char * buffer, std::size_t size) {
std::lock_guard Lock(LocalMutex_);
auto Device = SerialNumbers_.find(Utils::SerialNumberToInt(SerialNumber));
if(Device==SerialNumbers_.end() || Device->second.second== nullptr)
return false;
try {
return Device->second.second->SendRadiusCoAData(buffer,size);
} catch (...) {
poco_debug(Logger(),fmt::format(": SendRadiusCoAData: Could not send data to device '{}'", SerialNumber));
}
return false;
}
} //namespace

View File

@@ -19,7 +19,6 @@
#include "Poco/Net/SocketReactor.h"
#include "Poco/Net/ParallelSocketAcceptor.h"
#include "Poco/Net/SocketAcceptor.h"
#include "Poco/Timer.h"
#include "AP_WS_Connection.h"
#include "AP_WS_ReactorPool.h"
@@ -101,98 +100,41 @@ namespace OpenWifi {
[[nodiscard]] inline bool Running() const { return Running_; }
inline void AddConnection(std::uint64_t session_id, std::shared_ptr<AP_WS_Connection> Connection ) {
std::lock_guard Lock(LocalMutex_);
Sessions_[session_id] = std::make_pair(std::move(Connection),false);
std::unique_lock Lock(LocalMutex_);
Connections_[session_id] = Connection;
}
inline void DeleteConnection(std::uint64_t session_id) {
std::unique_lock Lock(LocalMutex_);
Connections_.erase(session_id);
}
inline std::shared_ptr<AP_WS_Connection> FindConnection(std::uint64_t session_id) const {
std::lock_guard Lock(LocalMutex_);
std::shared_lock Lock(LocalMutex_);
auto Connection = Sessions_.find(session_id);
if(Connection!=end(Sessions_))
return Connection->second.first;
auto Connection = Connections_.find(session_id);
if(Connection!=end(Connections_))
return Connection->second;
return nullptr;
}
inline bool GetStatistics(const std::string &SerialNumber, std::string & Statistics) const {
return GetStatistics(Utils::SerialNumberToInt(SerialNumber),Statistics);
}
bool GetStatistics(std::uint64_t SerialNumber, std::string & Statistics) const ;
inline bool GetState(const std::string & SerialNumber, GWObjects::ConnectionState & State) const {
return GetState(Utils::SerialNumberToInt(SerialNumber), State);
}
bool GetState(std::uint64_t SerialNumber, GWObjects::ConnectionState & State) const;
inline bool GetHealthcheck(const std::string &SerialNumber, GWObjects::HealthCheck & CheckData) const {
return GetHealthcheck(Utils::SerialNumberToInt(SerialNumber), CheckData);
}
bool GetHealthcheck(std::uint64_t SerialNumber, GWObjects::HealthCheck & CheckData) const ;
bool Connected(uint64_t SerialNumber) const ;
inline bool SendFrame(const std::string & SerialNumber, const std::string & Payload) const {
return SendFrame(Utils::SerialNumberToInt(SerialNumber), Payload);
}
bool SendFrame(std::uint64_t SerialNumber, const std::string & Payload) const ;
bool SendRadiusAuthenticationData(const std::string & SerialNumber, const unsigned char * buffer, std::size_t size);
bool SendRadiusAccountingData(const std::string & SerialNumber, const unsigned char * buffer, std::size_t size);
bool SendRadiusCoAData(const std::string & SerialNumber, const unsigned char * buffer, std::size_t size);
void SetSessionDetails(std::uint64_t connection_id, uint64_t SerialNumber);
bool EndSession(std::uint64_t connection_id, std::uint64_t serial_number);
void SetWebSocketTelemetryReporting(std::uint64_t RPCID, uint64_t SerialNumber, uint64_t Interval, uint64_t Lifetime);
void StopWebSocketTelemetry(std::uint64_t RPCID, uint64_t SerialNumber);
void SetKafkaTelemetryReporting(std::uint64_t RPCID, uint64_t SerialNumber, uint64_t Interval, uint64_t Lifetime);
void StopKafkaTelemetry(std::uint64_t RPCID, uint64_t SerialNumber);
void GetTelemetryParameters(uint64_t SerialNumber , bool & TelemetryRunning,
uint64_t & TelemetryInterval,
uint64_t & TelemetryWebSocketTimer,
uint64_t & TelemetryKafkaTimer,
uint64_t & TelemetryWebSocketCount,
uint64_t & TelemetryKafkaCount,
uint64_t & TelemetryWebSocketPackets,
uint64_t & TelemetryKafkaPackets);
void onGarbageCollecting(Poco::Timer & timer);
inline void AverageDeviceStatistics( std::uint64_t & Connections, std::uint64_t & AverageConnectionTime, std::uint64_t & NumberOfConnectingDevices) const {
Connections = NumberOfConnectedDevices_;
AverageConnectionTime = AverageDeviceConnectionTime_;
NumberOfConnectingDevices = NumberOfConnectingDevices_;
}
private:
mutable std::recursive_mutex LocalMutex_;
mutable std::shared_mutex LocalMutex_;
std::unique_ptr<Poco::Crypto::X509Certificate> IssuerCert_;
std::list<std::unique_ptr<Poco::Net::HTTPServer>> WebServers_;
Poco::Net::SocketReactor Reactor_;
Poco::Thread ReactorThread_;
std::string SimulatorId_;
Poco::ThreadPool DeviceConnectionPool_{"ws:dev-pool", 2, 64};
Poco::ThreadPool DeviceConnectionPool_{"ws:dev-pool", 2, 32};
bool LookAtProvisioning_ = false;
bool UseDefaultConfig_ = true;
bool SimulatorEnabled_=false;
std::unique_ptr<AP_WS_ReactorThreadPool> Reactor_pool_;
std::atomic_bool Running_=false;
std::map<std::uint64_t, std::pair<std::shared_ptr<AP_WS_Connection>,bool>> Sessions_;
std::map<std::uint64_t, std::pair<std::uint64_t,std::shared_ptr<AP_WS_Connection>>> SerialNumbers_;
std::map<std::uint64_t, std::shared_ptr<AP_WS_Connection>> Connections_;
std::atomic_bool AllowSerialNumberMismatch_=true;
std::atomic_uint64_t MismatchDepth_=2;
std::atomic_uint64_t NumberOfConnectedDevices_=0;
std::atomic_uint64_t AverageDeviceConnectionTime_=0;
std::atomic_uint64_t NumberOfConnectingDevices_=0;
std::vector<std::shared_ptr<AP_WS_Connection>> Garbage_;
std::unique_ptr<Poco::TimerCallback<AP_WS_Server>> GarbageCollectorCallback_;
Poco::Timer Timer_;
Poco::Thread GarbageCollector_;
AP_WS_Server() noexcept:
SubSystemServer("WebSocketServer", "WS-SVR", "ucentral.websocket") {
}

View File

@@ -13,7 +13,7 @@
#include "Poco/JSON/Parser.h"
#include "CommandManager.h"
#include "AP_WS_Server.h"
#include "DeviceRegistry.h"
#include "StorageService.h"
#include "framework/ow_constants.h"
@@ -41,7 +41,7 @@ namespace OpenWifi {
uint64_t ID = Payload.get(uCentralProtocol::ID);
poco_debug(Logger(),fmt::format("({}): Processing {} response.", SerialNumber, ID));
if (ID > 1) {
std::lock_guard Lock(LocalMutex_);
std::unique_lock Lock(LocalMutex_);
auto RPC = OutStandingRequests_.find(ID);
if (RPC == OutStandingRequests_.end() ||
RPC->second.SerialNumber !=
@@ -110,7 +110,7 @@ namespace OpenWifi {
}
void CommandManager::onJanitorTimer([[maybe_unused]] Poco::Timer & timer) {
std::lock_guard Lock(LocalMutex_);
std::unique_lock Lock(LocalMutex_);
Utils::SetThreadName("cmd:janitor");
Poco::Logger & MyLogger = Poco::Logger::get("CMD-MGR-JANITOR");
auto now = std::chrono::high_resolution_clock::now();
@@ -131,7 +131,7 @@ namespace OpenWifi {
}
bool CommandManager::IsCommandRunning(const std::string &C) {
std::lock_guard Lock(LocalMutex_);
std::shared_lock Lock(LocalMutex_);
for (const auto &request : OutStandingRequests_) {
if (request.second.UUID == C) {
return true;
@@ -178,7 +178,7 @@ namespace OpenWifi {
continue;
}
if (!AP_WS_Server()->Connected(
if (!DeviceRegistry()->Connected(
Utils::SerialNumberToInt(Cmd.SerialNumber))) {
poco_trace(
MyLogger,
@@ -268,7 +268,7 @@ namespace OpenWifi {
Idx.rpc_entry = disk_only ? nullptr : std::make_shared<CommandManager::promise_type_t>();
poco_debug(Logger(), fmt::format("{}: Sending command. ID: {}", UUID, RPCID));
if(AP_WS_Server()->SendFrame(SerialNumber, ToSend.str())) {
if(DeviceRegistry()->SendFrame(SerialNumber, ToSend.str())) {
if(!oneway_rpc) {
std::lock_guard M(Mutex_);
OutStandingRequests_[RPCID] = Idx;

View File

@@ -153,7 +153,7 @@ namespace OpenWifi {
}
inline bool CommandRunningForDevice(std::uint64_t SerialNumber, std::string & uuid, std::string &command) {
std::lock_guard Lock(LocalMutex_);
std::shared_lock Lock(LocalMutex_);
for(const auto &[Request,Command]:OutStandingRequests_) {
if(Command.SerialNumber==SerialNumber) {
@@ -166,7 +166,7 @@ namespace OpenWifi {
}
inline void ClearQueue(std::uint64_t SerialNumber) {
std::lock_guard Lock(LocalMutex_);
std::unique_lock Lock(LocalMutex_);
for(auto Request = OutStandingRequests_.begin(); Request != OutStandingRequests_.end() ; ) {
if(Request->second.SerialNumber==SerialNumber)
Request = OutStandingRequests_.erase(Request);
@@ -176,7 +176,7 @@ namespace OpenWifi {
}
private:
mutable std::recursive_mutex LocalMutex_;
mutable std::shared_mutex LocalMutex_;
std::atomic_bool Running_ = false;
Poco::Thread ManagerThread;
std::atomic_uint64_t Id_=3; // do not start @1. We ignore ID=1 & 0 is illegal..

View File

@@ -17,6 +17,7 @@
#include "AP_WS_Server.h"
#include "CommandManager.h"
#include "Daemon.h"
#include "DeviceRegistry.h"
#include "FileUploader.h"
#include "FindCountry.h"
#include "OUIServer.h"
@@ -43,7 +44,7 @@ namespace OpenWifi {
WebSocketClientServer(),
OUIServer(),
FindCountryFromIP(),
// DeviceRegistry(),
DeviceRegistry(),
CommandManager(),
FileUploader(),
StorageArchiver(),

View File

@@ -3,6 +3,7 @@
//
#include "Dashboard.h"
#include "DeviceRegistry.h"
#include "StorageService.h"
namespace OpenWifi {

View File

@@ -105,19 +105,18 @@ namespace OpenWifi {
}
bool DeviceRegistry::EndSession(std::uint64_t connection_id, std::uint64_t serial_number) {
std::unique_lock G(LocalMutex_);
std::unique_lock G(LocalMutex_);
auto Connection = SerialNumbers_.find(serial_number);
if (Connection == end(SerialNumbers_)) {
if(Connection==end(SerialNumbers_)) {
return false;
}
if (Connection->second.first != connection_id) {
if(Connection->second.first!=connection_id) {
return false;
}
SerialNumbers_.erase(Connection);
return true;
}

View File

@@ -21,26 +21,8 @@ namespace OpenWifi {
LatestOUIFileName_ = MicroService::instance().DataDir() + "/newOUIFile.txt";
CurrentOUIFileName_ = MicroService::instance().DataDir() + "/current_oui.txt";
bool Recovered = false;
Poco::File OuiFile(CurrentOUIFileName_);
if(OuiFile.exists()) {
std::unique_lock Lock(LocalMutex_);
Recovered = ProcessFile(CurrentOUIFileName_,OUIs_);
if(Recovered) {
poco_notice(Logger(),
fmt::format("Recovered last OUI file - {}", CurrentOUIFileName_));
}
} else {
poco_notice(Logger(),
fmt::format("No existing OUIFile.", CurrentOUIFileName_));
}
UpdaterCallBack_ = std::make_unique<Poco::TimerCallback<OUIServer>>(*this, &OUIServer::onTimer);
if(Recovered) {
Timer_.setStartInterval(60 * 60 * 1000); // first run in 1 hour
} else {
Timer_.setStartInterval(30 * 1000); // first run in 5 minutes
}
Timer_.setStartInterval(30 * 1000); // first run in 5 minutes
Timer_.setPeriodicInterval(7 * 24 * 60 * 60 * 1000);
Timer_.start(*UpdaterCallBack_, MicroService::instance().TimerPool());
return 0;
@@ -120,8 +102,6 @@ namespace OpenWifi {
return;
Updating_ = true;
poco_information(Logger(),"Starting to process OUI file...");
// fetch data from server, if not available, just use the file we already have.
Poco::File Current(CurrentOUIFileName_);
if(Current.exists()) {
@@ -142,7 +122,7 @@ namespace OpenWifi {
OUIMap TmpOUIs;
if(GetFile(LatestOUIFileName_) && ProcessFile(LatestOUIFileName_, TmpOUIs)) {
std::unique_lock G(LocalMutex_);
std::lock_guard G(Mutex_);
OUIs_ = std::move(TmpOUIs);
LastUpdate_ = OpenWifi::Now();
Poco::File F1(CurrentOUIFileName_);
@@ -154,18 +134,16 @@ namespace OpenWifi {
} else if(OUIs_.empty()) {
if(ProcessFile(CurrentOUIFileName_, TmpOUIs)) {
LastUpdate_ = OpenWifi::Now();
std::unique_lock G(LocalMutex_);
std::lock_guard G(Mutex_);
OUIs_ = std::move(TmpOUIs);
}
}
Initialized_=true;
Updating_ = false;
poco_information(Logger(),"Done processing OUI file...");
}
std::string OUIServer::GetManufacturer(const std::string &MAC) {
std::shared_lock Lock(LocalMutex_);
std::lock_guard Guard(Mutex_);
auto Manufacturer = OUIs_.find(Utils::SerialNumberToOUI(MAC));
if(Manufacturer != OUIs_.end())
return Manufacturer->second;

View File

@@ -4,8 +4,6 @@
#pragma once
#include <shared_mutex>
#include "framework/MicroService.h"
#include "Poco/Timer.h"
@@ -32,7 +30,6 @@ namespace OpenWifi {
[[nodiscard]] bool ProcessFile(const std::string &FileName, OUIMap &Map);
private:
std::shared_mutex LocalMutex_;
uint64_t LastUpdate_ = 0 ;
bool Initialized_ = false;
OUIMap OUIs_;

View File

@@ -3,8 +3,9 @@
//
#include "RADIUS_proxy_server.h"
#include "DeviceRegistry.h"
#include "RADIUS_helpers.h"
#include "AP_WS_Server.h"
namespace OpenWifi {
const int SMALLEST_RADIUS_PACKET = 20+19+4;
@@ -147,7 +148,7 @@ namespace OpenWifi {
auto CalledStationID = P.ExtractCalledStationID();
poco_information(Logger(), fmt::format("Accounting Packet received for {}, CalledStationID: {}, CallingStationID:{}",SerialNumber, CalledStationID, CallingStationID));
AP_WS_Server()->SendRadiusAccountingData(SerialNumber,P.Buffer(),P.Size());
DeviceRegistry()->SendRadiusAccountingData(SerialNumber,P.Buffer(),P.Size());
}
void RADIUS_proxy_server::OnAuthenticationSocketReadable(const Poco::AutoPtr<Poco::Net::ReadableNotification>& pNf) {
@@ -169,7 +170,7 @@ namespace OpenWifi {
auto CalledStationID = P.ExtractCalledStationID();
poco_information(Logger(), fmt::format("Authentication Packet received for {}, CalledStationID: {}, CallingStationID:{}",SerialNumber, CalledStationID, CallingStationID));
AP_WS_Server()->SendRadiusAuthenticationData(SerialNumber,P.Buffer(),P.Size());
DeviceRegistry()->SendRadiusAuthenticationData(SerialNumber,P.Buffer(),P.Size());
}
void RADIUS_proxy_server::OnCoASocketReadable(const Poco::AutoPtr<Poco::Net::ReadableNotification>& pNf) {
@@ -191,14 +192,10 @@ namespace OpenWifi {
auto CalledStationID = P.ExtractCalledStationID();
poco_information(Logger(), fmt::format("CoA Packet received for {}, CalledStationID: {}, CallingStationID:{}",SerialNumber, CalledStationID, CallingStationID));
AP_WS_Server()->SendRadiusCoAData(SerialNumber,P.Buffer(),P.Size());
DeviceRegistry()->SendRadiusCoAData(SerialNumber,P.Buffer(),P.Size());
}
void RADIUS_proxy_server::SendAccountingData(const std::string &serialNumber, const char *buffer, std::size_t size) {
if(Pools_.empty())
return;
RADIUS::RadiusPacket P((unsigned char *)buffer,size);
auto Destination = P.ExtractProxyStateDestination();
auto CallingStationID = P.ExtractCallingStationID();
@@ -234,10 +231,6 @@ namespace OpenWifi {
}
void RADIUS_proxy_server::SendAuthenticationData(const std::string &serialNumber, const char *buffer, std::size_t size) {
if(Pools_.empty())
return;
RADIUS::RadiusPacket P((unsigned char *)buffer,size);
auto Destination = P.ExtractProxyStateDestination();
auto CallingStationID = P.ExtractCallingStationID();
@@ -269,10 +262,6 @@ namespace OpenWifi {
}
void RADIUS_proxy_server::SendCoAData(const std::string &serialNumber, const char *buffer, std::size_t size) {
if(Pools_.empty())
return;
RADIUS::RadiusPacket P((unsigned char *)buffer,size);
auto Destination = P.ExtractProxyStateDestination();

View File

@@ -19,7 +19,7 @@
#include "Poco/TemporaryFile.h"
#include "RADIUS_helpers.h"
#include "AP_WS_Server.h"
#include "DeviceRegistry.h"
namespace OpenWifi {
@@ -82,13 +82,13 @@ namespace OpenWifi {
if (P.IsAuthentication()) {
auto SerialNumber = P.ExtractSerialNumberFromProxyState();
Logger_.debug(fmt::format("{}: {} Received {} bytes.", SerialNumber, P.PacketType(), NumberOfReceivedBytes));
AP_WS_Server()->SendRadiusAuthenticationData(
DeviceRegistry()->SendRadiusAuthenticationData(
SerialNumber, Buffer,
NumberOfReceivedBytes);
} else if (P.IsAccounting()) {
auto SerialNumber = P.ExtractSerialNumberFromProxyState();
Logger_.debug(fmt::format("{}: {} Received {} bytes.", SerialNumber, P.PacketType(), NumberOfReceivedBytes));
AP_WS_Server()->SendRadiusAccountingData(
DeviceRegistry()->SendRadiusAccountingData(
SerialNumber, Buffer,
NumberOfReceivedBytes);
} else if (P.IsAuthority()) {

View File

@@ -8,7 +8,7 @@
#include "RESTAPI_RPC.h"
#include "CommandManager.h"
#include "AP_WS_Server.h"
#include "DeviceRegistry.h"
#include "StorageService.h"
#include "framework/ow_constants.h"
#include "ParseWifiScan.h"
@@ -48,11 +48,11 @@ namespace OpenWifi::RESTAPI_RPC {
// then we should just add the command to
// the DB and let it figure out when to deliver the command.
auto SerialNumberInt = Utils::SerialNumberToInt(Cmd.SerialNumber);
if (Cmd.RunAt || (!AP_WS_Server()->Connected(SerialNumberInt) && RetryLater)) {
if (Cmd.RunAt || (!DeviceRegistry()->Connected(SerialNumberInt) && RetryLater)) {
Logger.information(fmt::format("{},{}: Command will be run in the future or when device is connected again.", Cmd.UUID, RPCID));
SetCommandStatus(Cmd, Request, Response, Handler, Storage::CommandExecutionType::COMMAND_PENDING, Logger);
return;
} else if ((!AP_WS_Server()->Connected(SerialNumberInt) && !RetryLater)){
} else if ((!DeviceRegistry()->Connected(SerialNumberInt) && !RetryLater)){
Logger.information(fmt::format("{},{}: Command canceled. Device is not connected. Command will not be retried.", Cmd.UUID, RPCID));
return SetCommandStatus(Cmd, Request, Response, Handler, Storage::CommandExecutionType::COMMAND_FAILED, Logger);
}

View File

@@ -13,6 +13,7 @@
#include "AP_WS_Server.h"
#include "CentralConfig.h"
#include "DeviceRegistry.h"
#include "FileUploader.h"
#include "RESTAPI_RPC.h"
#include "RESTAPI_device_commandHandler.h"
@@ -59,7 +60,7 @@ namespace OpenWifi {
} else if (Command_ == RESTAPI::Protocol::STATUS) {
return GetStatus();
} else if (Command_ == RESTAPI::Protocol::RTTY) {
if(!AP_WS_Server()->Connected(SerialNumberInt_)) {
if(!DeviceRegistry()->Connected(SerialNumberInt_)) {
CallCanceled(Command_.c_str(), RESTAPI::Errors::DeviceNotConnected);
return BadRequest(RESTAPI::Errors::DeviceNotConnected);
}
@@ -164,7 +165,7 @@ namespace OpenWifi {
for(const auto &Command:PostCommands) {
if(Command_==Command.Command) {
Poco::Thread::current()->setName(fmt::format("{}:{}:{}",Command.Command, TransactionId_,SerialNumber_));
if(Command.RequireConnection && !AP_WS_Server()->Connected(SerialNumberInt_)) {
if(Command.RequireConnection && !DeviceRegistry()->Connected(SerialNumberInt_)) {
CallCanceled(Command.Command, RESTAPI::Errors::DeviceNotConnected);
return BadRequest(RESTAPI::Errors::DeviceNotConnected);
}
@@ -215,7 +216,7 @@ namespace OpenWifi {
Poco::Thread::current()->id()));
if (QB_.LastOnly) {
std::string Stats;
if (AP_WS_Server()->GetStatistics(SerialNumber_, Stats)) {
if (DeviceRegistry()->GetStatistics(SerialNumber_, Stats)) {
Poco::JSON::Parser P;
if (Stats.empty())
Stats = uCentralProtocol::EMPTY_JSON_DOC;
@@ -262,7 +263,7 @@ namespace OpenWifi {
Poco::Thread::current()->id()));
GWObjects::ConnectionState State;
if (AP_WS_Server()->GetState(SerialNumber_, State)) {
if (DeviceRegistry()->GetState(SerialNumber_, State)) {
Poco::JSON::Object RetObject;
State.to_json(RetObject);
return ReturnObject(RetObject);
@@ -318,7 +319,7 @@ namespace OpenWifi {
if (QB_.LastOnly) {
GWObjects::HealthCheck HC;
if (AP_WS_Server()->GetHealthcheck(SerialNumber_, HC)) {
if (DeviceRegistry()->GetHealthcheck(SerialNumber_, HC)) {
Poco::JSON::Object Answer;
HC.to_json(Answer);
return ReturnObject(Answer);
@@ -508,7 +509,7 @@ namespace OpenWifi {
Params.stringify(ParamStream);
Cmd.Details = ParamStream.str();
// AP_WS_Server()->SetPendingUUID(SerialNumber_, NewUUID);
// DeviceRegistry()->SetPendingUUID(SerialNumber_, NewUUID);
return RESTAPI_RPC::WaitForCommand(CMD_RPC,true,Cmd, Params, *Request, *Response, timeout, nullptr, this, Logger_);
}
return BadRequest(RESTAPI::Errors::RecordNotUpdated);
@@ -1024,16 +1025,16 @@ namespace OpenWifi {
if(!StatusOnly) {
if (KafkaOnly) {
if (Interval) {
AP_WS_Server()->SetKafkaTelemetryReporting(CMD_RPC,IntSerialNumber, Interval, Lifetime);
DeviceRegistry()->SetKafkaTelemetryReporting(CMD_RPC,IntSerialNumber, Interval, Lifetime);
Answer.set("action", "Kafka telemetry started.");
Answer.set("uuid", CMD_UUID);
} else {
AP_WS_Server()->StopKafkaTelemetry(CMD_RPC,IntSerialNumber);
DeviceRegistry()->StopKafkaTelemetry(CMD_RPC,IntSerialNumber);
Answer.set("action", "Kafka telemetry stopped.");
}
} else {
if (Interval) {
AP_WS_Server()->SetWebSocketTelemetryReporting(CMD_RPC,IntSerialNumber, Interval,
DeviceRegistry()->SetWebSocketTelemetryReporting(CMD_RPC,IntSerialNumber, Interval,
Lifetime);
std::string EndPoint;
if (TelemetryStream()->CreateEndpoint(Utils::SerialNumberToInt(SerialNumber_), EndPoint, CMD_UUID)) {
@@ -1046,7 +1047,7 @@ namespace OpenWifi {
}
} else {
Answer.set("action", "WebSocket telemetry stopped.");
AP_WS_Server()->StopWebSocketTelemetry(CMD_RPC,IntSerialNumber);
DeviceRegistry()->StopWebSocketTelemetry(CMD_RPC,IntSerialNumber);
}
}
} else {
@@ -1057,7 +1058,7 @@ namespace OpenWifi {
uint64_t TelemetryWebSocketCount, TelemetryKafkaCount, TelemetryInterval,
TelemetryWebSocketTimer, TelemetryKafkaTimer, TelemetryWebSocketPackets,
TelemetryKafkaPackets;
AP_WS_Server()->GetTelemetryParameters(IntSerialNumber,TelemetryRunning,
DeviceRegistry()->GetTelemetryParameters(IntSerialNumber,TelemetryRunning,
TelemetryInterval,
TelemetryWebSocketTimer,
TelemetryKafkaTimer,

View File

@@ -6,17 +6,17 @@
#include "RESTObjects/RESTAPI_GWobjects.h"
#include "StorageService.h"
#include "AP_WS_Server.h"
#include "DeviceRegistry.h"
namespace OpenWifi {
inline void CompleteDeviceInfo(const GWObjects::Device & Device, Poco::JSON::Object & Answer) {
GWObjects::ConnectionState CS;
AP_WS_Server()->GetState(Device.SerialNumber,CS);
DeviceRegistry()->GetState(Device.SerialNumber,CS);
GWObjects::HealthCheck HC;
AP_WS_Server()->GetHealthcheck(Device.SerialNumber, HC);
DeviceRegistry()->GetHealthcheck(Device.SerialNumber, HC);
std::string Stats;
AP_WS_Server()->GetStatistics(Device.SerialNumber, Stats);
DeviceRegistry()->GetStatistics(Device.SerialNumber, Stats);
Poco::JSON::Object DeviceInfo;
Device.to_json(DeviceInfo);

View File

@@ -16,7 +16,6 @@
#include "RESTAPI/RESTAPI_device_helper.h"
#include "Poco/StringTokenizer.h"
#include "framework/orm.h"
#include "AP_WS_Server.h"
namespace OpenWifi {
@@ -62,7 +61,7 @@ namespace OpenWifi {
GWObjects::DeviceConnectionStatistics DCS;
Poco::JSON::Object Answer;
AP_WS_Server()->AverageDeviceStatistics(DCS.connectedDevices,DCS.averageConnectionTime, DCS.connectingDevices);
DeviceRegistry()->AverageDeviceStatistics(DCS.connectedDevices,DCS.averageConnectionTime, DCS.connectingDevices);
DCS.to_json(Answer);
return ReturnObject(Answer);
}

View File

@@ -11,7 +11,7 @@
#include "Daemon.h"
#ifdef TIP_GATEWAY_SERVICE
#include "AP_WS_Server.h"
#include "DeviceRegistry.h"
#include "CapabilitiesCache.h"
#endif
@@ -57,7 +57,7 @@ namespace OpenWifi::GWObjects {
#ifdef TIP_GATEWAY_SERVICE
ConnectionState ConState;
if (AP_WS_Server()->GetState(SerialNumber, ConState)) {
if (DeviceRegistry()->GetState(SerialNumber, ConState)) {
ConState.to_json(Obj);
} else {
field_to_json(Obj,"ipAddress", "");

View File

@@ -4,7 +4,7 @@
#include "framework/MicroService.h"
#include "AP_WS_Connection.h"
#include "AP_WS_Server.h"
#include "DeviceRegistry.h"
#include "TelemetryClient.h"
#include "TelemetryStream.h"
#include "CommandManager.h"
@@ -94,7 +94,7 @@ namespace OpenWifi {
void TelemetryClient::SendTelemetryShutdown() {
poco_information(Logger(),fmt::format("TELEMETRY-SHUTDOWN({}): Closing.",CId_));
AP_WS_Server()->StopWebSocketTelemetry(CommandManager()->NextRPCId(), SerialNumber_);
DeviceRegistry()->StopWebSocketTelemetry(CommandManager()->NextRPCId(), SerialNumber_);
TelemetryStream()->DeRegisterClient(UUID_);
delete this;
}

View File

@@ -6,7 +6,7 @@
#include "framework/MicroService.h"
#include "sdks/sdk_prov.h"
#include "AP_WS_Server.h"
#include "DeviceRegistry.h"
namespace OpenWifi {
@@ -89,7 +89,7 @@ namespace OpenWifi {
}
inline void SendToDevice(const std::string &SerialNumber,const std::string &Payload) {
AP_WS_Server()->SendFrame(SerialNumber,Payload);
DeviceRegistry()->SendFrame(SerialNumber,Payload);
}
inline void run() final {

View File

@@ -97,8 +97,6 @@ using namespace std::chrono_literals;
#include "Poco/Net/SocketNotification.h"
#include "Poco/Base64Decoder.h"
#include "Poco/ThreadLocal.h"
#include "Poco/NullChannel.h"
#include "cppkafka/cppkafka.h"
#include "framework/MicroServiceErrorHandler.h"
@@ -109,7 +107,6 @@ using namespace std::chrono_literals;
#include "nlohmann/json.hpp"
#include "ow_version.h"
#include "fmt/core.h"
#include "framework/MicroServiceErrorHandler.h"
#define _OWDEBUG_ std::cout<< __FILE__ <<":" << __LINE__ << std::endl;
// #define _OWDEBUG_ Logger().debug(Poco::format("%s: %lu",__FILE__,__LINE__));
@@ -3078,7 +3075,7 @@ namespace OpenWifi {
private:
std::vector<std::unique_ptr<Poco::Net::HTTPServer>> RESTServers_;
Poco::ThreadPool Pool_{"x-rest",8,128};
Poco::ThreadPool Pool_{"x-rest",32,128};
RESTAPI_GenericServer Server_;
RESTAPI_ExtServer() noexcept:
@@ -3212,7 +3209,7 @@ namespace OpenWifi {
const Poco::ThreadPool & Pool() { return Pool_; }
private:
std::vector<std::unique_ptr<Poco::Net::HTTPServer>> RESTServers_;
Poco::ThreadPool Pool_{"i-rest",4,64};
Poco::ThreadPool Pool_{"i-rest",32,96};
RESTAPI_GenericServer Server_;
RESTAPI_IntServer() noexcept:
@@ -3409,7 +3406,7 @@ namespace OpenWifi {
bool NoBuiltInCrypto_=false;
Poco::JWT::Signer Signer_;
Poco::Logger &Logger_;
Poco::ThreadPool TimerPool_{"timer:pool",2,32};
Poco::ThreadPool TimerPool_{"timer:pool",2,16};
std::unique_ptr<BusEventManager> BusEventManager_;
};
@@ -3574,43 +3571,23 @@ namespace OpenWifi {
auto LoggingDestination = MicroService::instance().ConfigGetString("logging.type", "file");
auto LoggingFormat = MicroService::instance().ConfigGetString("logging.format",
"%Y-%m-%d %H:%M:%S.%i %s: [%p][thr:%I] %t");
auto UseAsyncLogs_ = MicroService::instance().ConfigGetBool("logging.asynch",false);
if (LoggingDestination == "null") {
Poco::AutoPtr<Poco::NullChannel> DevNull(new Poco::NullChannel);
Poco::Logger::root().setChannel(DevNull);
} else if (LoggingDestination == "console") {
"%Y-%m-%d %H:%M:%S %s: [%p] %t");
if (LoggingDestination == "console") {
Poco::AutoPtr<Poco::ConsoleChannel> Console(new Poco::ConsoleChannel);
if(UseAsyncLogs_) {
Poco::AutoPtr<Poco::AsyncChannel> Async(new Poco::AsyncChannel(Console));
Poco::AutoPtr<Poco::PatternFormatter> Formatter(new Poco::PatternFormatter);
Formatter->setProperty("pattern", LoggingFormat);
Poco::AutoPtr<Poco::FormattingChannel> FormattingChannel(
new Poco::FormattingChannel(Formatter, Async));
Poco::Logger::root().setChannel(FormattingChannel);
} else {
Poco::AutoPtr<Poco::PatternFormatter> Formatter(new Poco::PatternFormatter);
Formatter->setProperty("pattern", LoggingFormat);
Poco::AutoPtr<Poco::FormattingChannel> FormattingChannel(
new Poco::FormattingChannel(Formatter, Console));
Poco::Logger::root().setChannel(FormattingChannel);
}
Poco::AutoPtr<Poco::AsyncChannel> Async(new Poco::AsyncChannel(Console));
Poco::AutoPtr<Poco::PatternFormatter> Formatter(new Poco::PatternFormatter);
Formatter->setProperty("pattern", LoggingFormat);
Poco::AutoPtr<Poco::FormattingChannel> FormattingChannel(
new Poco::FormattingChannel(Formatter, Async));
Poco::Logger::root().setChannel(FormattingChannel);
} else if (LoggingDestination == "colorconsole") {
Poco::AutoPtr<Poco::ColorConsoleChannel> ColorConsole(new Poco::ColorConsoleChannel);
if(UseAsyncLogs_) {
Poco::AutoPtr<Poco::AsyncChannel> Async(new Poco::AsyncChannel(ColorConsole));
Poco::AutoPtr<Poco::PatternFormatter> Formatter(new Poco::PatternFormatter);
Formatter->setProperty("pattern", LoggingFormat);
Poco::AutoPtr<Poco::FormattingChannel> FormattingChannel(
new Poco::FormattingChannel(Formatter, Async));
Poco::Logger::root().setChannel(FormattingChannel);
} else {
Poco::AutoPtr<Poco::PatternFormatter> Formatter(new Poco::PatternFormatter);
Formatter->setProperty("pattern", LoggingFormat);
Poco::AutoPtr<Poco::FormattingChannel> FormattingChannel(
new Poco::FormattingChannel(Formatter, ColorConsole));
Poco::Logger::root().setChannel(FormattingChannel);
}
Poco::AutoPtr<Poco::ColorConsoleChannel> Console(new Poco::ColorConsoleChannel);
Poco::AutoPtr<Poco::AsyncChannel> Async(new Poco::AsyncChannel(Console));
Poco::AutoPtr<Poco::PatternFormatter> Formatter(new Poco::PatternFormatter);
Formatter->setProperty("pattern", LoggingFormat);
Poco::AutoPtr<Poco::FormattingChannel> FormattingChannel(
new Poco::FormattingChannel(Formatter, Async));
Poco::Logger::root().setChannel(FormattingChannel);
} else if (LoggingDestination == "sql") {
//"CREATE TABLE T_POCO_LOG (Source VARCHAR, Name VARCHAR, ProcessId INTEGER, Thread VARCHAR, ThreadId INTEGER, Priority INTEGER, Text VARCHAR, DateTime DATE)"
@@ -3624,21 +3601,16 @@ namespace OpenWifi {
FileChannel->setProperty("rotation", "10 M");
FileChannel->setProperty("archive", "timestamp");
FileChannel->setProperty("path", LoggingLocation);
if(UseAsyncLogs_) {
Poco::AutoPtr<Poco::AsyncChannel> Async_File(
new Poco::AsyncChannel(FileChannel));
Poco::AutoPtr<Poco::PatternFormatter> Formatter(new Poco::PatternFormatter);
Formatter->setProperty("pattern", LoggingFormat);
Poco::AutoPtr<Poco::FormattingChannel> FormattingChannel(
new Poco::FormattingChannel(Formatter, Async_File));
Poco::Logger::root().setChannel(FormattingChannel);
} else {
Poco::AutoPtr<Poco::PatternFormatter> Formatter(new Poco::PatternFormatter);
Formatter->setProperty("pattern", LoggingFormat);
Poco::AutoPtr<Poco::FormattingChannel> FormattingChannel(
new Poco::FormattingChannel(Formatter, FileChannel));
Poco::Logger::root().setChannel(FormattingChannel);
}
Poco::AutoPtr<Poco::AsyncChannel> Async_File(new Poco::AsyncChannel(FileChannel));
Poco::AutoPtr<Poco::AsyncChannel> Async_Muxer(new Poco::AsyncChannel(LogMuxer()));
Poco::AutoPtr<Poco::SplitterChannel> Splitter(new Poco::SplitterChannel);
Splitter->addChannel(Async_File);
Splitter->addChannel(Async_Muxer);
Poco::AutoPtr<Poco::PatternFormatter> Formatter(new Poco::PatternFormatter);
Formatter->setProperty("pattern", LoggingFormat);
Poco::AutoPtr<Poco::FormattingChannel> FormattingChannel(
new Poco::FormattingChannel(Formatter, Splitter));
Poco::Logger::root().setChannel(FormattingChannel);
}
auto Level = Poco::Logger::parseLevel(MicroService::instance().ConfigGetString("logging.level", "debug"));
Poco::Logger::root().setLevel(Level);

View File

@@ -64,7 +64,7 @@ namespace OpenWifi {
{
if(!Valid_ || !Registered_)
return;
std::lock_guard G(Mutex_);
std::shared_lock G(Mutex_);
try {
int flags;
Poco::Buffer<char> IncomingFrame(0);

View File

@@ -38,7 +38,7 @@ namespace OpenWifi {
std::unique_ptr<Poco::Net::WebSocket> WS_;
Poco::Logger &Logger_;
std::string Sid_;
std::recursive_mutex Mutex_;
std::shared_mutex Mutex_;
volatile bool Valid_=false;
volatile bool Registered_=false;

View File

@@ -108,7 +108,7 @@ namespace OpenWifi {
Utils::SetThreadName("rt:janitor");
static auto LastStats = OpenWifi::Now();
std::lock_guard Lock(LocalMutex_);
std::unique_lock Lock(LocalMutex_);
for(auto element=EndPoints_.begin();element!=EndPoints_.end();) {
if(element->second->TooOld()) {
auto c = fmt::format("Removing {}. Serial: {} Device connection time: {}s. Client connection time: {}s",
@@ -153,7 +153,7 @@ namespace OpenWifi {
while (NextNotification && NotificationManagerRunning_) {
auto Notification = dynamic_cast<RTTYS_Notification *>(NextNotification.get());
if (Notification != nullptr) {
std::lock_guard Lock(LocalMutex_);
std::unique_lock Lock(LocalMutex_);
auto It = EndPoints_.find(Notification->id_);
if (It != EndPoints_.end()) {
switch (Notification->type_) {
@@ -197,7 +197,7 @@ namespace OpenWifi {
}
bool RTTYS_server::SendToClient(const std::string &Id, const u_char *Buf, std::size_t Len) {
std::lock_guard Lock(LocalMutex_);
std::shared_lock Lock(LocalMutex_);
try {
auto It = EndPoints_.find(Id);
@@ -213,7 +213,7 @@ namespace OpenWifi {
}
bool RTTYS_server::SendToClient(const std::string &Id, const std::string &s) {
std::lock_guard Lock(LocalMutex_);
std::shared_lock Lock(LocalMutex_);
try {
auto It = EndPoints_.find(Id);
@@ -229,7 +229,7 @@ namespace OpenWifi {
}
bool RTTYS_server::SendKeyStrokes(const std::string &Id, const u_char *buffer, std::size_t len) {
std::lock_guard Lock(LocalMutex_);
std::shared_lock Lock(LocalMutex_);
auto It=EndPoints_.find(Id);
if(It==EndPoints_.end() || It->second==nullptr) {
@@ -247,7 +247,7 @@ namespace OpenWifi {
}
bool RTTYS_server::WindowSize(const std::string &Id, int cols, int rows) {
std::lock_guard Lock(LocalMutex_);
std::shared_lock Lock(LocalMutex_);
auto It=EndPoints_.find(Id);
if(It==EndPoints_.end() || It->second==nullptr) {
@@ -275,7 +275,7 @@ namespace OpenWifi {
}
bool RTTYS_server::ValidId(const std::string &Token) {
std::lock_guard Lock(LocalMutex_);
std::shared_lock Lock(LocalMutex_);
return EndPoints_.find(Token) != EndPoints_.end();
}

View File

@@ -276,7 +276,7 @@ namespace OpenWifi {
std::unique_ptr<Poco::TimerCallback<RTTYS_server>> GCCallBack_;
std::list<std::unique_ptr<RTTYS_Device_ConnectionHandler>> FailedDevices;
std::list<std::unique_ptr<RTTYS_ClientConnection>> FailedClients;
std::recursive_mutex LocalMutex_;
std::shared_mutex LocalMutex_;
std::atomic_uint64_t TotalEndPoints_=0;
std::atomic_uint64_t FailedNumDevices_=0;

View File

@@ -13,7 +13,7 @@
#include "Poco/Data/RecordSet.h"
#include "Daemon.h"
#include "AP_WS_Server.h"
#include "DeviceRegistry.h"
#include "StorageService.h"
#include "FileUploader.h"
@@ -265,7 +265,7 @@ typedef Poco::Tuple<
Offset++;
GWObjects::CommandDetails R;
ConvertCommandRecord(i,R);
if (AP_WS_Server()->Connected(Utils::SerialNumberToInt(R.SerialNumber)))
if (DeviceRegistry()->Connected(Utils::SerialNumberToInt(R.SerialNumber)))
Commands.push_back(R);
}
@@ -476,7 +476,7 @@ typedef Poco::Tuple<
for(const auto &i : Records) {
GWObjects::CommandDetails R;
ConvertCommandRecord(i,R);
if (AP_WS_Server()->Connected(Utils::SerialNumberToInt(R.SerialNumber)))
if (DeviceRegistry()->Connected(Utils::SerialNumberToInt(R.SerialNumber)))
Commands.push_back(R);
}
return true;

View File

@@ -11,7 +11,7 @@
#include "CentralConfig.h"
#include "ConfigurationCache.h"
#include "Daemon.h"
#include "AP_WS_Server.h"
#include "DeviceRegistry.h"
#include "FindCountry.h"
#include "OUIServer.h"
#include "Poco/Data/RecordSet.h"
@@ -727,17 +727,17 @@ namespace OpenWifi {
UpdateCountedMap(Dashboard.deviceType, DeviceType);
GWObjects::ConnectionState ConnState;
if(AP_WS_Server()->GetState(SerialNumber, ConnState)) {
if(DeviceRegistry()->GetState(SerialNumber, ConnState)) {
UpdateCountedMap(Dashboard.status, ConnState.Connected ? "connected" : "not connected");
UpdateCountedMap(Dashboard.certificates, ComputeCertificateTag(ConnState.VerifiedCertificate));
UpdateCountedMap(Dashboard.lastContact, ComputeUpLastContactTag(ConnState.LastContact));
GWObjects::HealthCheck HC;
if(AP_WS_Server()->GetHealthcheck(SerialNumber,HC))
if(DeviceRegistry()->GetHealthcheck(SerialNumber,HC))
UpdateCountedMap(Dashboard.healths, ComputeSanityTag(HC.Sanity));
else
UpdateCountedMap(Dashboard.healths, ComputeSanityTag(100));
std::string LastStats;
if(AP_WS_Server()->GetStatistics(SerialNumber, LastStats) && !LastStats.empty()) {
if(DeviceRegistry()->GetStatistics(SerialNumber, LastStats) && !LastStats.empty()) {
Poco::JSON::Parser P;
auto RawObject = P.parse(LastStats).extract<Poco::JSON::Object::Ptr>();

View File

@@ -6,7 +6,7 @@
// Arilia Wireless Inc.
//
#include "AP_WS_Server.h"
#include "DeviceRegistry.h"
#include "StorageService.h"
namespace OpenWifi {

View File

@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
# wait-for-postgres.sh
set -e
@@ -20,7 +20,7 @@ if [ "$1" = '/openwifi/owgw' -a "$(id -u)" = '0' ]; then
if [ "$RUN_CHOWN" = 'true' ]; then
chown -R "$OWGW_USER": "$OWGW_ROOT" "$OWGW_CONFIG"
fi
exec gosu "$OWGW_USER" "$@"
exec su-exec "$OWGW_USER" "$@"
fi
exec "$@"