Updating n2n

This commit is contained in:
Scott Duensing 2023-09-07 18:23:07 -05:00
parent eb240ff4f2
commit c68ec92614
29 changed files with 203 additions and 95 deletions

3
.gitignore vendored
View file

@ -3,3 +3,6 @@ output.log
bin/
hamncheese/export_presets.cfg
temp/
scp.sh
start-edge.sh
console-edge.sh

View file

@ -1,3 +1,15 @@
#
# Things to do:
# - Add libzstd
#
# Issues to watch:
# - https://github.com/ntop/n2n/issues/1090 (P2P connections still occupy server traffic)
# - https://github.com/ntop/n2n/issues/1087 (Slow shutdown on Windows)
# - https://github.com/ntop/n2n/issues/1082 (A large ping value every 20 seconds)
# - https://github.com/ntop/n2n/issues/610 (n2nGaming Application?)
# - https://github.com/ntop/n2n/issues/934 (Upnp is missing)
#
extends Control

View file

@ -2,6 +2,7 @@ extends Node
var _server: HttpServer = null
var _client: HTTPRequest
var _userInfo: Dictionary
# This array is of dictionary elements that contain:
@ -13,11 +14,19 @@ var _userInfo: Dictionary
var peerArray: Array
func _http_request_completed(result, response_code, headers, body):
print("HTTP: ", result, " ", response_code)
func _process(_delta):
pass
func _ready():
# DEBUG - See if using the VPN fixes our peer removal issue.
_client = HTTPRequest.new()
add_child(_client)
_client.request_completed.connect(self._http_request_completed)
clear()
@ -96,4 +105,9 @@ func update(peersFromCPP: Array):
print("Peers After: ", peerArray)
# DEBUG - See if using the VPN fixes our peer removal issue.
var error = _client.request("http://" + _server.bind_address + ":" + str(_server.port))
if error != OK:
push_error("An error occurred in the HTTP request.")
return changed

View file

@ -74,4 +74,4 @@ env_n2nvpn.Append(CCFLAGS=['-g', '-O2'])
# Check with the documentation of the external library to see which library
# files should be included/linked.
#env.Append(LIBS=['lib1', 'lib2'])
env.Append(LIBS=['pthread'])

View file

@ -1,6 +1,3 @@
/* include/config.h. Generated from config.h.in by configure. */
/* include/config.h.in. Generated from configure.ac by autoheader. */
/* Define to 1 if you have the `cap' library (-lcap). */
/* #undef HAVE_LIBCAP */
@ -17,7 +14,7 @@
/* #undef HAVE_LIBPCAP */
/* Define to 1 if you have the `pthread' library (-lpthread). */
/* #undef HAVE_LIBPTHREAD */
#define HAVE_LIBPTHREAD 1
/* Define to 1 if you have the `zstd' library (-lzstd). */
/* #undef HAVE_LIBZSTD */

View file

@ -24,14 +24,7 @@ build
.idea
.vscode
.vs
packages/debian/debian/changelog
packages/debian/debian/control
packages/debian/debian/files
packages/debian/debian/rules
packages/etc/systemd/system/edge-ntopng@.service
packages/etc/systemd/system/edge.service
packages/etc/systemd/system/edge@.service
packages/etc/systemd/system/supernode.service
*dSYM*
__pycache__

View file

@ -1,9 +1,19 @@
#
# Change it according to your setup
#
# Prerequisite: apt-get install devscripts
#
#
N2N_HOME=$(PWD)/../..
N2N_BUILD=${N2N_HOME}/packages/debian/n2n
include ${N2N_HOME}/config.mak
# TODO: continue to untangle the version generation
# we either should not need to override the config.mak here or
# should never set the version in config.mak and always calculate it
PACKAGE_VERSION := $(shell ${N2N_HOME}/scripts/version.sh)
all: clean pkg
pkg:
@ -19,7 +29,8 @@ pkg:
install -m644 ../../community.list ${N2N_BUILD}/usr/share/doc/n2n/examples/
install -m644 ../../doc/*.md ${N2N_BUILD}/usr/share/doc/n2n/
@/bin/rm -f ../n2n*.deb
dpkg-buildpackage -rfakeroot -d -us -uc -a@EXTN@
DEBEMAIL=builder@example.com dch -v ${PACKAGE_VERSION} --no-auto-nmu Auto Build
dpkg-buildpackage -rfakeroot -d -us -uc --host-type ${CONFIG_HOST}
-dpkg-sig --sign builder -k D1EB60BE ../n2n_*deb
@\rm -f ../n2n_*dsc ../n2n_*.gz ../n2n_*changes
@/bin/mv ../n2n_*deb .

View file

@ -1,6 +1,6 @@
Prerequisites
-------------
apt-get install debhelper fakeroot dpkg-sig
apt-get install debhelper fakeroot dpkg-sig devscripts
EdgeOS
------

View file

@ -0,0 +1,3 @@
AC_INIT([Makefile.in], 1.0)
# TODO: Remove this file before the next stable release
echo "This configure script is no longer needed, update your build system"

View file

@ -1,60 +0,0 @@
AC_INIT([Makefile.in], 1.0)
AC_ARG_WITH(edgex, [ --with-edgex Build for Ubiquity-X])
# NOTE: this file is not actually used. You need to edit configure as well!
N2N_VERSION=$(../../scripts/version.sh)
DEBIAN_VERSION=`cat /etc/debian_version | grep "^8" | wc -l`
EXTRA_DEP=""
if test $DEBIAN_VERSION = "0"; then
EXTRA_DEP=", libzstd1"
fi
if test "${EXTN+set}" != set; then
MACHINE=`uname -m`
SHORT_MACHINE=`echo $MACHINE | cut -b1-3`
if test $MACHINE = "x86_64"; then
EXTN="amd64"
else
if test $SHORT_MACHINE = "aar"; then
EXTN="arm64"
else
if test $SHORT_MACHINE = "arm"; then
EXTN="armhf"
else
if test $SHORT_MACHINE = "mip"; then
EXTN="mips"
else
EXTN="i386"
fi
fi
fi
fi
fi
if test "${with_edgex+set}" = set; then
EXTN="mipsel"
fi
APP=n2n
DATE=`date -R`
AC_SUBST(APP)
AC_SUBST(N2N_VERSION)
AC_SUBST(EXTN)
AC_SUBST(DATE)
AC_SUBST(EXTRA_DEP)
AC_CONFIG_FILES(debian/changelog)
AC_CONFIG_FILES(debian/files)
AC_CONFIG_FILES(debian/control)
AC_CONFIG_FILES(debian/rules)
AC_CONFIG_FILES(../etc/systemd/system/edge.service)
AC_CONFIG_FILES(../etc/systemd/system/edge@.service)
AC_CONFIG_FILES(../etc/systemd/system/edge-ntopng@.service)
AC_CONFIG_FILES(../etc/systemd/system/supernode.service)
AC_CONFIG_FILES(Makefile)
AC_OUTPUT

View file

@ -0,0 +1,4 @@
n2n (3.0) table; urgency=high
* Last stable release
-- Luca Deri <deri@ntop.org> Wed, 27 Oct 2021 20:43:08 +0200

View file

@ -1,4 +0,0 @@
@APP@ (@N2N_VERSION@) table; urgency=high
* Last packaged version
-- Luca Deri <deri@ntop.org> @DATE@

View file

@ -6,9 +6,9 @@ Standards-Version: 4.6.0
Build-Depends:
Package: n2n
Architecture: @EXTN@
Architecture: any
Suggests: uml-utilities
Depends: ${shlibs:Depends}, ${misc:Depends} @EXTRA_DEP@
Depends: ${shlibs:Depends}, ${misc:Depends}
Conflicts: n2n (<< 2.1.0-1)
Replaces: n2n (<< 2.1.0-1)
Description: a layer-two peer-to-peer virtual private network (VPN)

View file

@ -1 +0,0 @@
n2n_@N2N_VERSION@_@EXTN@.deb free optional

View file

@ -12,7 +12,7 @@
# http://www.tin.org/bin/man.cgi?section=7&topic=debhelper
#
package=@APP@
package=n2n
build: build-stamp
build-stamp:
@ -50,6 +50,7 @@ binary-arch: build install
cp -r ../etc debian/n2n
find debian/n2n -name "*.in" -exec /bin/rm {} ';'
find debian/n2n -name "*~" -exec /bin/rm {} ';'
dh_shlibdeps --dpkg-shlibdeps-params=--ignore-missing-info
dh_link
dh_gencontrol
dh_md5sums

View file

@ -48,9 +48,5 @@ AC_SUBST(DATE)
AC_SUBST(RPM_SIGN_CMD)
AC_CONFIG_FILES(n2n.spec)
AC_CONFIG_FILES(../etc/systemd/system/edge.service)
AC_CONFIG_FILES(../etc/systemd/system/edge@.service)
AC_CONFIG_FILES(../etc/systemd/system/edge-ntopng@.service)
AC_CONFIG_FILES(../etc/systemd/system/supernode.service)
AC_CONFIG_FILES(Makefile)
AC_OUTPUT

View file

@ -7,6 +7,7 @@ import argparse
import socket
import json
import collections
import time
class JsonUDP():
@ -171,6 +172,28 @@ def str_table(rows, columns, orderby):
return ''.join(result)
def num2timestr(seconds):
"""Convert a number of seconds into a human time"""
if seconds == 0:
return "now"
days, seconds = divmod(seconds, (60*60*24))
hours, seconds = divmod(seconds, (60*60))
minutes, seconds = divmod(seconds, 60)
r = []
if days:
r += [f"{days}d"]
if hours:
r += [f"{hours}h"]
if minutes:
r += [f"{minutes}m"]
if seconds:
r += [f"{seconds}s"]
return "".join(r)
def subcmd_show_supernodes(rpc, args):
rows = rpc.read('supernodes')
columns = [
@ -179,8 +202,13 @@ def subcmd_show_supernodes(rpc, args):
'macaddr',
'sockaddr',
'uptime',
'last_seen',
]
now = int(time.time())
for row in rows:
row["last_seen"] = num2timestr(now - row["last_seen"])
return str_table(rows, columns, args.orderby)
@ -192,8 +220,13 @@ def subcmd_show_edges(rpc, args):
'macaddr',
'sockaddr',
'desc',
'last_seen',
]
now = int(time.time())
for row in rows:
row["last_seen"] = num2timestr(now - row["last_seen"])
return str_table(rows, columns, args.orderby)

View file

@ -607,7 +607,7 @@ void readFromMgmtSocket (n2n_edge_t *eee) {
msg_len += snprintf((char *) (udp_buf + msg_len), (N2N_PKT_BUF_SIZE - msg_len),
"%-19s %1s%1s | %-17s | %-21s | %-15s | %9s | %10s\n",
peer->version,
(peer->purgeable == false) ? "l" : "",
(peer->purgeable) ? "" : "l",
(peer == eee->curr_sn) ? (eee->sn_wait ? "." : "*" ) : "",
is_null_mac(peer->mac_addr) ? "" : macaddr_str(mac_buf, peer->mac_addr),
sock_to_cstr(sockbuf, &(peer->sock)),

View file

@ -683,6 +683,7 @@ static void register_with_new_peer (n2n_edge_t *eee,
scan->sock = *peer;
scan->timeout = eee->conf.register_interval; /* TODO: should correspond to the peer supernode registration timeout */
scan->last_valid_time_stamp = initial_time_stamp();
scan->purgeable = true;
if(via_multicast)
scan->local = 1;
@ -1903,6 +1904,7 @@ static int check_query_peer_info (n2n_edge_t *eee, time_t now, n2n_mac_t mac) {
scan->timeout = eee->conf.register_interval; /* TODO: should correspond to the peer supernode registration timeout */
scan->last_seen = now; /* Don't change this it marks the pending peer for removal. */
scan->last_valid_time_stamp = initial_time_stamp();
scan->purgeable = true;
HASH_ADD_PEER(eee->pending_peers, scan);
}

View file

@ -528,6 +528,7 @@ struct peer_info* add_sn_to_list_by_mac_or_sock (struct peer_info **sn_list, n2n
if(peer) {
sn_selection_criterion_default(&(peer->selection_criterion));
peer->last_valid_time_stamp = initial_time_stamp();
peer->purgeable = true;
memcpy(&(peer->sock), sock, sizeof(n2n_sock_t));
memcpy(peer->mac_addr, mac, sizeof(n2n_mac_t));
HASH_ADD_PEER(*sn_list, peer);
@ -687,7 +688,7 @@ size_t clear_peer_list (struct peer_info ** peer_list) {
size_t retval = 0;
HASH_ITER(hh, *peer_list, scan, tmp) {
if (scan->purgeable == false && scan->ip_addr) {
if (!scan->purgeable && scan->ip_addr) {
free(scan->ip_addr);
}
HASH_DEL(*peer_list, scan);

View file

@ -371,7 +371,7 @@ int process_mgmt (n2n_sn_t *sss,
ressize += snprintf(resbuf + ressize, N2N_SN_PKTBUF_SIZE - ressize,
"%s '%s'\n",
(community->is_federation) ? "FEDERATION" : ((community->purgeable == false) ? "FIXED NAME COMMUNITY" : "COMMUNITY"),
(community->is_federation) ? "FEDERATION" : ((community->purgeable) ? "COMMUNITY" : "FIXED NAME COMMUNITY"),
(community->is_federation) ? "-/-" : community->community);
sendto_mgmt(sss, sender_sock, sock_size, (const uint8_t *) resbuf, ressize);
ressize = 0;
@ -382,7 +382,7 @@ int process_mgmt (n2n_sn_t *sss,
ressize += snprintf(resbuf + ressize, N2N_SN_PKTBUF_SIZE - ressize,
"%4u | %-19s | %-17s | %-21s %-3s | %-15s | %9s\n",
++num,
(peer->dev_addr.net_addr == 0) ? ((peer->purgeable == false) ? "-l" : "") : ip_subnet_to_str(ip_bit_str, &peer->dev_addr),
(peer->dev_addr.net_addr == 0) ? ((peer->purgeable) ? "" : "-l") : ip_subnet_to_str(ip_bit_str, &peer->dev_addr),
(is_null_mac(peer->mac_addr)) ? "" : macaddr_str(mac_buf, peer->mac_addr),
sock_to_cstr(sockbuf, &(peer->sock)),
((peer->socket_fd >= 0) && (peer->socket_fd != sss->sock)) ? "TCP" : "",

View file

@ -1145,6 +1145,9 @@ static int update_edge (n2n_sn_t *sss,
/* Known */
if(auth_edge(&(scan->auth), &(reg->auth), answer_auth, comm) == 0) {
if(!sock_equal(sender_sock, &(scan->sock))) {
scan->dev_addr.net_addr = reg->dev_addr.net_addr;
scan->dev_addr.net_bitlen = reg->dev_addr.net_bitlen;
memcpy((char*)scan->dev_desc, reg->dev_desc, N2N_DESC_SIZE);
memcpy(&(scan->sock), sender_sock, sizeof(n2n_sock_t));
scan->socket_fd = socket_fd;
scan->last_cookie = reg->cookie;
@ -1480,7 +1483,7 @@ static int purge_expired_communities (n2n_sn_t *sss,
}
}
if((comm->edges == NULL) && (comm->purgeable == true)) {
if((comm->edges == NULL) && (comm->purgeable)) {
traceEvent(TRACE_INFO, "purging idle community %s", comm->community);
if(NULL != comm->header_encryption_ctx_static) {
/* this should not happen as 'purgeable' and thus only communities w/o encrypted header here */

View file

@ -1,6 +1,7 @@
#include <ctime>
#include <sys/time.h>
#include "stddclmr.h"
#include "n2nvpn.h"
extern "C" {

95
modules/n2nvpn/stddclmr.h Normal file
View file

@ -0,0 +1,95 @@
#ifndef STDDCLMR_H
#define STDDCLMR_H
/*
Action figures sold separately. Add toner. All models over 18 years of age.
All rights reserved. Allow four to six weeks for delivery. An equal
opportunity employer. Any resemblance to actual persons, living or dead, is
unintentional and purely coincidental. Apply only to affected area. Approved
for veterans. As seen on TV. At participating locations only. Avoid contact
with mucous membranes. Avoid contact with skin. Avoid extreme temperatures
and store in a cool dry place. Batteries not included. Be sure each item is
properly endorsed. Beware of dog. Booths for two or more. Breaking seal
constitutes acceptance of agreement. Call toll free number before digging.
Caveat emptor. Check here if tax deductible. Close cover before striking
Colors may fade. Contains a substantial amount of non-tobacco ingredients.
Contents may settle during shipment. Contestants have been briefed on some
questions before the show. Copyright 1995 Joker's Wild. Disclaimer does
not cover hurricane, lightning, tornado, tsunami, volcanic eruption,
earthquake, flood, and other Acts of God, misuse, neglect, unauthorized
repair, damage from improper installation, broken antenna or marred cabinet,
incorrect line voltage, missing or altered serial numbers, sonic boom
vibrations, electromagnetic radiation from nuclear blasts, customer
adjustments that are not covered in the joke list, and incidents owing to
airplane crash, ship sinking, motor vehicle accidents, leaky roof, broken
glass, falling rocks, mud slides, forest fire, flying projectiles, or
dropping the item. Do not bend, fold, mutilate, or spindle. Do not place
near flammable or magnetic source. Do not puncture, incinerate, or store
above 120 degrees Fahrenheit. Do not stamp. Use other side for additional
listings. Do not use while operating a motor vehicle or heavy equipment. Do
not write below this line. Documents are provided "as is" without any
warranties expressed or implied. Don't quote me on anything. Don't quote me
on that. Driver does not carry cash. Drop in any mailbox. Edited for
television. Employees and their families are not eligible. Falling rock.
First pull up, then pull down. Flames redirected to /dev/null. For a
limited time only. For external use only. For off-road use only. For office
use only. For recreational use only. Do not disturb. Freshest if eaten
before date on carton. Hand wash only, tumble dry on low heat. If a rash,
redness, irritation, or swelling develops, discontinue use. If condition
persists, consult your physician. If defects are discovered, do not attempt
to fix them yourself, but return to an authorized service center. If
ingested, do not induce vomiting, if symptoms persist, consult a doctor.
Keep away from open flames and avoid inhaling fumes. Keep away from
sunlight, pets, and small children. Keep cool; process promptly. Limit
one-per-family please. Limited time offer, call now to ensure prompt
delivery. List at least two alternate dates. List each check separately by
bank number. List was current at time of printing. Lost ticket pays maximum
rate. May be too intense for some viewers. Must be 18 to enter. No Canadian
coins. No alcohol, dogs or horses. No anchovies unless otherwise specified.
No animals were harmed in the production of these documents. No money down.
No other warranty expressed or implied. No passes accepted for this
engagement. No postage necessary if mailed in the United States. No
preservatives added. No purchase necessary. No salt, MSG, artificial color
or flavor added. No shoes, no shirt, no service, no kidding. No solicitors.
No substitutions allowed. No transfers issued until the bus comes to a
complete stop. No user-serviceable parts inside. Not affiliated with the
American Red Cross. Not liable for damages due to use or misuse. Not
recommended for children. Not responsible for direct, indirect, incidental
or consequential damages resulting from any defect, error or failure to
perform. Not the Beatles. Objects in mirror may be closer than they appear.
One size fits all. Many suitcases look alike. Other copyright laws for
specific entries apply wherever noted. Other restrictions may apply. Package
sold by weight, not volume. Parental advisory - explicit lyrics. Penalty for
private use. Place stamp here. Please remain seated until the ride has come
to a complete stop. Possible penalties for early withdrawal. Post office will
not deliver without postage. Postage will be paid by addressee. Prerecorded
for this time zone. Price does not include taxes. Processed at location
stamped in code at top of carton. Quantities are limited while supplies last.
Read at your own risk. Record additional transactions on back of previous
stub. Replace with same type. Reproduction strictly prohibited. Restaurant
package, not for resale. Return to sender, no forwarding order on file,
unable to forward. Safety goggles may be required during use. Sanitized for
your protection. Sealed for your protection, do not use if the safety seal is
broken. See label for sequence. Shading within a garment may occur. Sign here
without admitting guilt. Simulated picture. Slightly enlarged to show detail.
Slightly higher west of the Rockies. Slippery when wet. Smoking these may be
hazardous to your health. Some assembly required. Some equipment shown is
optional. Some of the trademarks mentioned in this product appear for
identification purposes only. Subject to FCC approval. Subject to change
without notice. Substantial penalty for early withdrawal. Text may contain
material some readers may find objectionable, parental guidance is advised.
Text used in these documents is made from 100% recycled electrons and magnetic
particles. These documents do not reflect the thoughts or opinions of either
myself, my company, my friends, or my rabbit. This is not an offer to sell
securities. This offer is void where prohibited, taxed, or otherwise
restricted. This product is meant for educational purposes only. Times
approximate. Unix is a registered trademark of AT&T. Use only as directed. Use
only in a well-ventilated are. User assumes full liabilities. Void where
prohibited. We have sent the forms which seem right for you. You must be
present to win. You need not be present to win. Your canceled check is your
receipt. Your mileage may vary. I didn't do it. You can't prove anything.
This supersedes all previous notices.
*/
#endif // STDDCLMR_H

View file

@ -6,10 +6,14 @@ mkdir -p bin
pushd modules/n2nvpn/n2n
./autogen.sh
./configure
make supernode
./configure --enable-pthread
#--enable-miniupnp --enable-natpmp
make
#supernode
mv supernode ../../../bin/.
make clean
rm include/config.h
mv edge ../../../bin/.
#make clean
#rm include/config.h
popd