0
0
mirror of https://github.com/cjdelisle/cjdns synced 2025-10-06 00:32:50 +02:00

Fixed bug caused by 2 switch pingers

Got public peering logic SEEMINGLY working
Excluded special address ranges for reporting as a peering address
This commit is contained in:
Caleb James DeLisle
2024-09-24 23:22:30 +02:00
parent 0ecf3e6466
commit 67d13b99d3
22 changed files with 268 additions and 72 deletions

11
.clangd
View File

@@ -1,3 +1,12 @@
CompileFlags: # Tweak the parse settings, example directory given to show format
Add:
- "-I./node_build/dependencies/libuv/include"
- "-DPARANOIA=1"
- "-DIdentity_CHECK=1"
- "-DCJDNS_RAND_U64_PER_FILE=1"
- "-Wall"
- "-Wextra"
Diagnostics:
Suppress:
- "pointer-sign"
- "sign-compare"

14
Cargo.lock generated
View File

@@ -514,6 +514,7 @@ dependencies = [
"cjdns-keys",
"env_logger 0.11.5",
"hex",
"ipnetwork 0.20.0",
"libc",
"log",
"num_cpus",
@@ -1090,6 +1091,15 @@ dependencies = [
"serde",
]
[[package]]
name = "ipnetwork"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf466541e9d546596ee94f9f69590f89473455f88372423e0008fc1a7daf100e"
dependencies = [
"serde",
]
[[package]]
name = "is_terminal_polyfill"
version = "1.70.1"
@@ -1436,7 +1446,7 @@ version = "0.29.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8750e073f82219c01e771133c64718d7685aef922da8a0d430a46aed05b6341a"
dependencies = [
"ipnetwork",
"ipnetwork 0.18.0",
"pnet_base",
"pnet_datalink",
"pnet_packet",
@@ -1456,7 +1466,7 @@ version = "0.29.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f85aef5e52e22ff06b1b11f2eb6d52959a9e0ecad3cb3f5cc2d78cadc077f0e"
dependencies = [
"ipnetwork",
"ipnetwork 0.18.0",
"libc",
"pnet_base",
"pnet_sys",

View File

@@ -49,4 +49,5 @@ cc = "1.0"
cbindgen = { version = "0.16" }
bindgen = { version = "0.55" }
byteorder = "1.5"
trust-dns-resolver = "0.23.2"
trust-dns-resolver = "0.23.2"
ipnetwork = "0.20"

View File

@@ -376,7 +376,7 @@ Err_DEFUN Core_init(struct Allocator* alloc,
UpperDistributor_admin_register(nc->upper, admin, alloc);
RouteGen_admin_register(rg, admin, alloc);
InterfaceController_admin_register(nc->ifController, admin, alloc);
SwitchPinger_admin_register(nc->sp, admin, alloc);
SwitchPinger_admin_register(spf->sp, admin, alloc);
UDPInterface_admin_register(
eventBase, alloc, logger, admin, nc->ifController, globalConf);
#ifdef HAS_ETH_INTERFACE

View File

@@ -385,42 +385,39 @@ static Iface_DEFUN incomingFromCore(Message_t* msg, struct Iface* coreIf)
struct Control* ctrl = (struct Control*) Message_bytes(msg);
if (ctrl->header.type_be == Control_ERROR_be) {
const uint16_t t = ctrl->header.type_be;
if (t == Control_ERROR_be) {
return handleError(msg, ch, label, labelStr, &routeHdr);
} else if (ctrl->header.type_be == Control_KEYPING_be
|| ctrl->header.type_be == Control_PING_be)
{
return handlePing(msg, ch, label, labelStr, ctrl->header.type_be);
} else if (ctrl->header.type_be == Control_KEYPONG_be
|| ctrl->header.type_be == Control_PONG_be
|| ctrl->header.type_be == Control_LlAddr_REPLY_be)
{
Log_debug(ch->log, "got switch pong [%d] from [%s]",
ctrl->header.type_be, labelStr);
Err(Message_epush(msg, &routeHdr, RouteHeader_SIZE));
return Iface_next(&ch->pub.switchPingerIf, msg);
} else if (ctrl->header.type_be == Control_GETSNODE_QUERY_be) {
} else if (t == Control_KEYPING_be || t == Control_PING_be) {
return handlePing(msg, ch, label, labelStr, t);
} else if (t == Control_GETSNODE_QUERY_be) {
return handleGetSnodeQuery(msg, ch, label, labelStr);
} else if (ctrl->header.type_be == Control_GETSNODE_REPLY_be
|| ctrl->header.type_be == Control_RPATH_REPLY_be)
} else if (t == Control_RPATH_QUERY_be) {
return handleRPathQuery(msg, ch, label, labelStr);
} else if (t == Control_LlAddr_QUERY_be) {
return handleLlAddrQuery(msg, ch, label, labelStr);
} else if (
t == Control_PONG_be ||
t == Control_KEYPONG_be ||
t == Control_LlAddr_REPLY_be ||
t == Control_GETSNODE_REPLY_be ||
t == Control_RPATH_REPLY_be)
{
Log_debug(ch->log, "got %s REPLY from [%s]",
(ctrl->header.type_be == Control_GETSNODE_REPLY_be) ? "GETSNODE" : "RPATH",
labelStr);
if (t == Control_PONG_be) {
// Special case for IfController which has it's own pinger
int32_t offset = Message_getLength(msg) - 12;
uint8_t* ptr = &Message_bytes(msg)[offset];
if (!Bits_memcmp(ptr, "IFACE_CNTRLR", 12)) {
Log_debug(ch->log, "IFC switch pong from [%s]", labelStr);
Err(Message_epush(msg, &routeHdr, RouteHeader_SIZE));
return Iface_next(&ch->pub.ifcSwitchPingerIf, msg);
}
}
Log_debug(ch->log, "Got [%d] REPLY from [%s]", t, labelStr);
Err(Message_epush(msg, &routeHdr, RouteHeader_SIZE));
Err(Message_epush32be(msg, 0xffffffff));
Err(Message_epush32be(msg, PFChan_Core_CTRL_MSG));
return Iface_next(&ch->eventIf, msg);
} else if (ctrl->header.type_be == Control_RPATH_QUERY_be) {
return handleRPathQuery(msg, ch, label, labelStr);
} else if (ctrl->header.type_be == Control_LlAddr_QUERY_be) {
return handleLlAddrQuery(msg, ch, label, labelStr);
}
Log_info(ch->log, "DROP control packet of unknown type from [%s], type [%d]",
@@ -433,7 +430,7 @@ static Iface_DEFUN incomingFromCore(Message_t* msg, struct Iface* coreIf)
static Iface_DEFUN incomingFromSwitchPinger(Message_t* msg, struct Iface* switchPingerIf)
{
struct ControlHandler_pvt* ch =
Identity_containerOf(switchPingerIf, struct ControlHandler_pvt, pub.switchPingerIf);
Identity_containerOf(switchPingerIf, struct ControlHandler_pvt, pub.ifcSwitchPingerIf);
return Iface_next(&ch->pub.coreIf, msg);
}
@@ -512,7 +509,7 @@ struct ControlHandler* ControlHandler_new(struct Allocator* allocator,
ch->ifc = ifc;
Bits_memcpy(ch->myPublicKey, myPublicKey, 32);
ch->pub.coreIf.send = incomingFromCore;
ch->pub.switchPingerIf.send = incomingFromSwitchPinger;
ch->pub.ifcSwitchPingerIf.send = incomingFromSwitchPinger;
ch->eventIf.send = changeSnode;
EventEmitter_regCore(ee, &ch->eventIf, PFChan_Pathfinder_SNODE);
Identity_set(ch);

View File

@@ -31,7 +31,8 @@ struct ControlHandler
* This interface expects and sends [ SwitchHeader ][ 0xffffffff ][ CTRL frame ]
* May send a pong or an error caused by a ping.
*/
struct Iface switchPingerIf;
// ONLY receives ping messages which have "IFACE_CNTRLR" in the payload, everything else is an event.
struct Iface ifcSwitchPingerIf;
};
struct ControlHandler* ControlHandler_new(struct Allocator* alloc,

View File

@@ -331,7 +331,7 @@ static void sendPing(struct Peer* ep)
struct SwitchPinger_Ping* ping =
SwitchPinger_newPing(ep->addr.path,
String_CONST(""),
String_CONST("IFACE_CNTRLR"),
ic->timeoutMilliseconds,
onPingResponse,
ep->alloc,

View File

@@ -23,7 +23,6 @@
#include "net/ControlHandler.h"
#include "net/InterfaceController.h"
#include "interface/Iface.h"
#include "tunnel/IpTunnel.h"
#include "net/EventEmitter.h"
#include "net/SessionManager.h"
#include "net/UpperDistributor.h"
@@ -63,7 +62,10 @@ struct NetCore* NetCore_new(uint8_t* privateKey,
struct UpperDistributor* upper = nc->upper = UpperDistributor_new(alloc, log, ee, myAddress);
Iface_plumb(&sm->insideIf, &upper->sessionManagerIf);
struct SwitchPinger* sp = nc->sp = SwitchPinger_new(base, rand, log, myAddress, alloc);
// NEVER USE THIS SWITCHPINGER
// It is legacy and only for iface controller.
// Replies will NOT be routed to this sp unless they are PING and have the code "IFACE_CNTRLR" in them.
struct SwitchPinger* sp = SwitchPinger_new(base, rand, log, myAddress, alloc);
struct InterfaceController* ifc = nc->ifController =
InterfaceController_new(
@@ -74,7 +76,7 @@ struct NetCore* NetCore_new(uint8_t* privateKey,
Iface_plumb(&controlHandler->coreIf, &upper->controlHandlerIf);
Iface_plumb(&controlHandler->switchPingerIf, &sp->controlHandlerIf);
Iface_plumb(&controlHandler->ifcSwitchPingerIf, &sp->controlHandlerIf);
struct TUNAdapter* tunAdapt = nc->tunAdapt = TUNAdapter_new(alloc, log, myAddress->ip6.bytes);
Iface_plumb(&tunAdapt->upperDistributorIf, &upper->tunAdapterIf);

View File

@@ -44,7 +44,6 @@ struct NetCore
struct Address* myAddress;
struct SwitchCore* switchCore;
struct ControlHandler* controlHandler;
struct SwitchPinger* sp;
struct InterfaceController* ifController;
struct SessionManager* sm;
struct UpperDistributor* upper;

View File

@@ -116,14 +116,14 @@ static void adminPing(Dict* args, void* vcontext, String* txid, struct Allocator
adminPingOnResponse,
context->alloc,
context->switchPinger);
if (keyPing && *keyPing) {
ping->type = SwitchPinger_Type_KEYPING;
} else if (lladdr && *lladdr) {
ping->type = SwitchPinger_Type_LLADDR;
}
if (!ping) {
err = "no open slots to store ping, try later.";
} else {
if (keyPing && *keyPing) {
ping->type = SwitchPinger_Type_KEYPING;
} else if (lladdr && *lladdr) {
ping->type = SwitchPinger_Type_LLADDR;
}
ping->onResponseContext = Allocator_clone(ping->pingAlloc, (&(struct Ping) {
.context = context,
.txid = String_clone(txid, ping->pingAlloc),

View File

@@ -31,6 +31,7 @@ async-trait = { workspace = true }
env_logger = { workspace = true }
byteorder = { workspace = true }
trust-dns-resolver = { workspace = true }
ipnetwork = { workspace = true }
[build_dependencies]
cc = { workspace = true }

View File

@@ -290,6 +290,12 @@ RTypes_Error_t *Rffi_Seeder_public_peer(Rffi_Seeder *seeder,
const String_t *code,
Allocator_t *alloc);
RTypes_Error_t *Rffi_Seeder_public_status(Rffi_Seeder *seeder,
String_t **ipv4_out,
String_t **ipv6_out,
String_t **peer_id_out,
Allocator_t *alloc);
RTypes_Error_t *Rffi_Seeder_got_peers(Rffi_Seeder *seeder,
const String_t *peers,
Allocator_t *alloc);

View File

@@ -148,6 +148,28 @@ pub unsafe extern "C" fn Rffi_Seeder_public_peer(
std::ptr::null_mut()
}
#[no_mangle]
pub unsafe extern "C" fn Rffi_Seeder_public_status(
seeder: *mut Rffi_Seeder,
ipv4_out: *mut *mut String_t,
ipv6_out: *mut *mut String_t,
peer_id_out: *mut *mut String_t,
alloc: *mut Allocator_t,
) -> *mut RTypes_Error_t {
let s = identity::from_c!(seeder);
let st = s.seeder.get_status();
if let Some(v4) = st.v4 {
*ipv4_out = strc(alloc, v4);
}
if let Some(v6) = st.v6 {
*ipv6_out = strc(alloc, v6);
}
if let Some(peer_id) = st.peer_id {
*peer_id_out = strc(alloc, peer_id);
}
std::ptr::null_mut()
}
#[no_mangle]
pub extern "C" fn Rffi_Seeder_got_peers(
seeder: *mut Rffi_Seeder,

View File

@@ -4,11 +4,12 @@ use cjdns_keys::{CJDNSPublicKey, PublicKey};
use parking_lot::Mutex;
use tokio::sync::mpsc;
use byteorder::{ReadBytesExt,WriteBytesExt,BE};
use ipnetwork::{Ipv4Network,Ipv6Network};
use cjdns::bytes::{dnsseed::{CjdnsPeer, CjdnsTxtRecord}, message::Message as RMessage};
use trust_dns_resolver::config::{ResolverConfig, ResolverOpts};
use crate::{cffi::{self, Control_LlAddr_Udp4_t, Control_LlAddr_Udp6_t, Control_LlAddr_t, PFChan_Node}, external::interface::iface::{Iface, IfacePvt}, interface::wire::message::Message, util::now_ms};
use crate::{bytestring::ByteString, cffi::{self, Control_LlAddr_Udp4_t, Control_LlAddr_Udp6_t, Control_LlAddr_t, PFChan_Node}, external::interface::iface::{Iface, IfacePvt}, interface::wire::message::Message, util::now_ms};
#[derive(Default)]
struct SeederState {
@@ -261,7 +262,15 @@ struct MyPeeringInfo {
v6: Option<SocketAddrV6>,
}
pub struct SeederStatus {
pub v4: Option<String>,
pub v6: Option<String>,
pub peer_id: Option<String>,
}
pub struct Seeder {
special_ranges6: Vec<Ipv6Network>,
special_ranges4: Vec<Ipv4Network>,
my_pubkey: PublicKey,
inner: Arc<SeederInner>,
mpi: Mutex<MyPeeringInfo>,
@@ -277,6 +286,12 @@ impl Seeder {
fn got_lladdr4(&self, lla: &Control_LlAddr_Udp4_t) -> bool {
let sa =
SocketAddrV4::new(lla.addr.into(), u16::from_be(lla.port_be));
for r in &self.special_ranges4 {
if (*r).contains(*sa.ip()) {
log::debug!("got_lladdr() discard {} because it's local", sa.to_string());
return false;
}
}
let mut m = self.mpi.lock();
if let Some(v4) = &mut m.v4 {
if v4 == &sa {
@@ -295,6 +310,12 @@ impl Seeder {
fn got_lladdr6(&self, lla: &Control_LlAddr_Udp6_t) -> bool {
let sa = SocketAddrV6::new(
lla.addr.into(), u16::from_be(lla.port_be), 0, 0);
for r in &self.special_ranges6 {
if (*r).contains(*sa.ip()) {
log::debug!("got_lladdr() discard {} because it's local", sa.to_string());
return false;
}
}
let mut m = self.mpi.lock();
if let Some(v6) = &mut m.v6 {
if v6 == &sa {
@@ -398,6 +419,26 @@ impl Seeder {
);
}
pub fn get_status(&self) -> SeederStatus {
let m = self.mpi.lock();
let v4 = m.v4.map(|x|x.to_string());
let v6 = m.v6.map(|x|x.to_string());
let peer_id = m.passwd.as_ref().map(|p|p.code.clone());
drop(m);
let peer_id = if let Some(peer_id) = peer_id {
let len = peer_id.len();
let ds = ByteString(peer_id).into_debug_string();
if ds.len() > len {
Some(String::new() + "hex(" + &ds + ")")
} else {
Some(ds)
}
} else {
None
};
SeederStatus{ v4, v6, peer_id }
}
pub fn add_dns_seed(&self, seed: String, trust_snode: bool) {
let mut ds = self.inner.dns_seeds.lock();
for (s, t) in ds.iter_mut() {
@@ -418,6 +459,44 @@ impl Seeder {
self.inner.dns_seeds.lock().clone()
}
pub fn new(my_pubkey: CJDNSPublicKey) -> (Self, Iface) {
let special_ranges6: Vec<Ipv6Network> = vec![
"::/128".parse().unwrap(),
"::1/128".parse().unwrap(),
"::ffff:0:0/96".parse().unwrap(),
"::ffff:0:0:0/96".parse().unwrap(),
"64:ff9b::/96".parse().unwrap(),
"64:ff9b:1::/48".parse().unwrap(),
"100::/64".parse().unwrap(),
"2001::/32".parse().unwrap(),
"2001:20::/28".parse().unwrap(),
"2001:db8::/32".parse().unwrap(),
"2002::/16".parse().unwrap(),
"3fff::/20".parse().unwrap(),
"5f00::/16".parse().unwrap(),
"fc00::/7".parse().unwrap(),
"fe80::/64".parse().unwrap(),
"ff00::/8".parse().unwrap(),
];
let special_ranges4: Vec<Ipv4Network> = vec![
"0.0.0.0/8".parse().unwrap(),
"10.0.0.0/8".parse().unwrap(),
"100.64.0.0/10".parse().unwrap(),
"127.0.0.0/8".parse().unwrap(),
"169.254.0.0/16".parse().unwrap(),
"172.16.0.0/12".parse().unwrap(),
"192.0.0.0/24".parse().unwrap(),
"192.0.2.0/24".parse().unwrap(),
"192.88.99.0/24".parse().unwrap(),
"192.168.0.0/16".parse().unwrap(),
"198.18.0.0/15".parse().unwrap(),
"198.51.100.0/24".parse().unwrap(),
"203.0.113.0/24".parse().unwrap(),
"224.0.0.0/4".parse().unwrap(),
"233.252.0.0/24".parse().unwrap(),
"240.0.0.0/4".parse().unwrap(),
"255.255.255.255/32".parse().unwrap(),
];
let (_done, done_r) = mpsc::channel(1);
let (send_message, recv_message) = mpsc::channel(512);
let (mut iface, ifacep) = Iface::new(format!("Seeder()"));
@@ -431,6 +510,8 @@ impl Seeder {
tokio::task::spawn(Arc::clone(&inner).run(recv_message, done_r));
(
Self {
special_ranges4,
special_ranges6,
my_pubkey,
inner,
_done,

View File

@@ -81,7 +81,7 @@ static void ipQueryResp(struct SwitchPinger_Response* resp, void* userData)
// Since there was a change, post ASAP.
pq->lastPostTimeSec = 0;
}
break;
return;
case SwitchPinger_Result_LABEL_MISMATCH: err = "LABEL_MISMATCH"; break;
case SwitchPinger_Result_WRONG_DATA: err = "WRONG_DATA"; break;
case SwitchPinger_Result_ERROR_RESPONSE: err = "ERROR_RESPONSE"; break;
@@ -99,17 +99,20 @@ static void publicIPQuery(PeeringSeeder_pvt_t* pq) {
}
uint64_t now = Time_currentTimeSeconds();
if (pq->lastQueryTimeSec + 10 < now) {
if (pq->lastQueryTimeSec + 10 > now) {
Log_debug(pq->log, "Last query within 10 seconds");
return;
}
if (Rffi_Seeder_has_lladdr(pq->seeder)) {
if (pq->lastQueryTimeSec + 300 < now) {
if (pq->lastQueryTimeSec + 300 > now) {
Log_debug(pq->log, "Last query within 5 minutes and we have our lladdr");
return;
}
}
int peerCount = ReachabilityCollector_peerCount(pq->rc);
if (!peerCount) {
Log_debug(pq->log, "No peers");
return;
}
int tryPeerN = (pq->lastPeerQueried + 1) % peerCount;
@@ -117,13 +120,12 @@ static void publicIPQuery(PeeringSeeder_pvt_t* pq) {
struct ReachabilityCollector_PeerInfo* tryPeer =
ReachabilityCollector_getPeerInfo(pq->rc, tryPeerN);
struct Allocator* alloc = Allocator_child(pq->alloc);
struct SwitchPinger_Ping* q = SwitchPinger_newPing(
tryPeer->addr.path,
String_new("", alloc),
NULL,
10000,
ipQueryResp,
alloc,
pq->alloc,
pq->sp);
q->onResponseContext = pq;
q->type = SwitchPinger_Type_LLADDR;
@@ -133,7 +135,7 @@ static void publicIPQuery(PeeringSeeder_pvt_t* pq) {
Log_debug(pq->log, "Sent LlAddr query to [%s]", peerAddr->bytes);
}
static void snodeResp(Dict* msg, struct Address* src, struct MsgCore_Promise* prom)
static void snodeResp(Dict* msg, Gcc_UNUSED struct Address* src, struct MsgCore_Promise* prom)
{
PeeringSeeder_pvt_t* pq = Identity_check((PeeringSeeder_pvt_t*) prom->userData);
String* peers = Dict_getStringC(msg, "pr");
@@ -152,7 +154,7 @@ static void cycle(void* vpq)
return;
}
Log_debug(pq->log, "cycle()");
// Log_debug(pq->log, "cycle()");
// Try to get our IP if we can
publicIPQuery(pq);
@@ -211,6 +213,20 @@ void PeeringSeeder_setSnode(PeeringSeeder_t* self, struct Address* snode)
}
}
Err_DEFUN PeeringSeeder_publicStatus(PeeringSeeder_PublicStatus_t** outP, PeeringSeeder_t* self, Allocator_t* alloc)
{
PeeringSeeder_pvt_t* pq = Identity_check((PeeringSeeder_pvt_t*) self);
PeeringSeeder_PublicStatus_t* out = Allocator_calloc(alloc, sizeof(PeeringSeeder_PublicStatus_t), 1);
out->active = pq->active;
if (!Bits_isZero(&pq->snode, sizeof pq->snode)) {
out->snode = Address_toString(&pq->snode, alloc);
}
Err(Rffi_Seeder_public_status(
pq->seeder, &out->ipv4, &out->ipv6, &out->peerId, alloc));
*outP = out;
return NULL;
}
Err_DEFUN PeeringSeeder_publicPeer(PeeringSeeder_t* self, String_t* code, Allocator_t* reqAlloc)
{
PeeringSeeder_pvt_t* pq = Identity_check((PeeringSeeder_pvt_t*) self);

View File

@@ -31,6 +31,16 @@ typedef struct PeeringSeeder {
Iface_t* seederIface;
} PeeringSeeder_t;
typedef struct PeeringSeeder_PublicStatus {
bool active;
String_t* peerId;
String_t* ipv4;
String_t* ipv6;
String_t* snode;
} PeeringSeeder_PublicStatus_t;
Err_DEFUN PeeringSeeder_publicStatus(PeeringSeeder_PublicStatus_t** outP, PeeringSeeder_t* self, Allocator_t* alloc);
void PeeringSeeder_setSnode(PeeringSeeder_t* self, struct Address* snode);
#define PeeringSeeder_publicPeer_ID_MAX_LEN 30

View File

@@ -19,6 +19,7 @@
#include "rust/cjdns_sys/RTypes.h"
#include "rust/cjdns_sys/Rffi.h"
#include "subnode/PeeringSeeder.h"
#include "util/Gcc.h"
#include "util/Identity.h"
struct Context {
@@ -76,7 +77,7 @@ static void rmDnsSeed(Dict* args, void* vcontext, String* txid, struct Allocator
}
}
static void listDnsSeeds(Dict* args, void* vcontext, String* txid, struct Allocator* requestAlloc)
static void listDnsSeeds(Gcc_UNUSED Dict* args, void* vcontext, String* txid, struct Allocator* requestAlloc)
{
struct Context* ctx = Identity_check((struct Context*) vcontext);
Rffi_Seeder* rs = PeeringSeeder_getRsSeeder(ctx->sp);
@@ -116,6 +117,34 @@ static void publicPeer(Dict* args, void* vcontext, String* txid, struct Allocato
reply(ctx, txid, requestAlloc, err);
}
static void publicStatus(Gcc_UNUSED Dict* args, void* vcontext, String* txid, struct Allocator* requestAlloc)
{
struct Context* ctx = Identity_check((struct Context*) vcontext);
PeeringSeeder_PublicStatus_t* out = NULL;
RTypes_Error_t* er = PeeringSeeder_publicStatus(&out, ctx->sp, requestAlloc);
if (er) {
char* err = Rffi_printError(er, requestAlloc);
reply(ctx, txid, requestAlloc, err);
return;
}
Dict_t* reply = Dict_new(requestAlloc);
if (out->ipv4) {
Dict_putStringC(reply, "ipv4", out->ipv4, requestAlloc);
}
if (out->ipv6) {
Dict_putStringC(reply, "ipv6", out->ipv6, requestAlloc);
}
if (out->peerId) {
Dict_putStringC(reply, "peerId", out->peerId, requestAlloc);
}
if (out->snode) {
Dict_putStringC(reply, "snode", out->snode, requestAlloc);
}
Dict_putStringCC(reply, "error", "none", requestAlloc);
Admin_sendMessage(reply, txid, ctx->admin);
}
void PeeringSeeder_admin_register(PeeringSeeder_t* sp,
struct Admin* admin,
struct Allocator* alloc)
@@ -144,4 +173,6 @@ void PeeringSeeder_admin_register(PeeringSeeder_t* sp,
((struct Admin_FunctionArg[]) {
{ .name = "peerID", .required = false, .type = "String" }
}), admin);
Admin_registerFunctionNoArgs("PeeringSeeder_publicStatus", publicStatus, ctx, true, admin);
}

View File

@@ -13,13 +13,13 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "subnode/ReachabilityAnnouncer.h"
#include "subnode/PeeringSeeder.h"
#include "util/events/Timeout.h"
#include "util/Identity.h"
#include "util/events/Time.h"
#include "wire/Announce.h"
#include "crypto/AddressCalc.h"
#include "crypto/Sign.h"
#include "switch/LabelSplicer.h"
#include "util/AddrTools.h"
#include "util/Hex.h"
#include "util/Hash.h"
@@ -196,6 +196,7 @@ struct ReachabilityAnnouncer_pvt
struct SupernodeHunter* snh;
struct EncodingScheme* myScheme;
struct ReachabilityCollector* rc;
PeeringSeeder_t* ps;
String* encodingSchemeStr;
struct Announce_ItemHeader* mySchemeItem;
@@ -751,10 +752,12 @@ static void onSnodeChange(struct SupernodeHunter* sh,
AddrTools_printPath(newPath, sh->snodeAddr.path);
Log_debug(rap->log, "Change Supernode path [%s] -> [%s]", oldPath, newPath);
Bits_memcpy(&rap->snode, &sh->snodeAddr, Address_SIZE);
PeeringSeeder_setSnode(rap->ps, &rap->snode);
return;
}
Bits_memcpy(&rap->snode, &sh->snodeAddr, Address_SIZE);
PeeringSeeder_setSnode(rap->ps, &rap->snode);
rap->clockSkew = clockSkew;
stateReset(rap);
}
@@ -785,7 +788,8 @@ struct ReachabilityAnnouncer* ReachabilityAnnouncer_new(struct Allocator* alloca
struct SupernodeHunter* snh,
uint8_t* privateKey,
struct EncodingScheme* myScheme,
struct ReachabilityCollector* rc)
struct ReachabilityCollector* rc,
PeeringSeeder_t* ps)
{
struct Allocator* alloc = Allocator_child(allocator);
struct ReachabilityAnnouncer_pvt* rap =
@@ -801,6 +805,7 @@ struct ReachabilityAnnouncer* ReachabilityAnnouncer_new(struct Allocator* alloca
rap->myScheme = myScheme;
rap->encodingSchemeStr = EncodingScheme_serialize(myScheme, alloc);
rap->rc = rc;
rap->ps = ps;
rap->mySchemeItem =
(struct Announce_ItemHeader*) mkEncodingSchemeItem(alloc, rap->encodingSchemeStr);

View File

@@ -15,8 +15,8 @@
#ifndef ReachabilityAnnouncer_H
#define ReachabilityAnnouncer_H
#include "benc/String.h"
#include "dht/Address.h"
#include "subnode/PeeringSeeder.h"
#include "util/events/EventBase.h"
#include "util/log/Log.h"
#include "crypto/random/Random.h"
@@ -45,6 +45,7 @@ struct ReachabilityAnnouncer* ReachabilityAnnouncer_new(struct Allocator* alloca
struct SupernodeHunter* snh,
uint8_t* privateKey,
struct EncodingScheme* myScheme,
struct ReachabilityCollector* rc);
struct ReachabilityCollector* rc,
PeeringSeeder_t* ps);
#endif

View File

@@ -39,6 +39,7 @@
#include "wire/DataHeader.h"
#include "util/CString.h"
#include "wire/Metric.h"
#include "util/Gcc.h"
#include "subnode/ReachabilityAnnouncer.h"
@@ -80,7 +81,6 @@ struct SubnodePathfinder_pvt
struct Map_OfPromiseByQuery queryMap;
struct SwitchPinger* sp;
struct Iface switchPingerIf;
struct EncodingScheme* myScheme;
@@ -121,7 +121,7 @@ static Iface_DEFUN sendNode(Message_t* msg,
return Iface_next(&pf->pub.eventIf, msg);
}
static Iface_DEFUN connected(struct SubnodePathfinder_pvt* pf, Message_t* msg)
static Iface_DEFUN connected(struct SubnodePathfinder_pvt* pf, Gcc_UNUSED Message_t* msg)
{
Log_debug(pf->log, "INIT");
pf->state = SubnodePathfinder_pvt_state_RUNNING;
@@ -293,7 +293,7 @@ struct Ping {
Identity
};
static void pingReply(Dict* msg, struct Address* src, struct MsgCore_Promise* prom)
static void pingReply(Gcc_UNUSED Dict* msg, struct Address* src, struct MsgCore_Promise* prom)
{
struct Ping* usp = Identity_check((struct Ping*) prom->userData);
struct SubnodePathfinder_pvt* pf = Identity_check(usp->pf);
@@ -421,7 +421,7 @@ static Iface_DEFUN sessionEnded(Message_t* msg, struct SubnodePathfinder_pvt* pf
return NULL;
}
static Iface_DEFUN discoveredPath(Message_t* msg, struct SubnodePathfinder_pvt* pf)
static Iface_DEFUN discoveredPath(Gcc_UNUSED Message_t* msg, Gcc_UNUSED struct SubnodePathfinder_pvt* pf)
{
//struct Address addr = {0};
//addressForNode(&addr, msg);
@@ -437,8 +437,9 @@ static Iface_DEFUN handlePing(Message_t* msg, struct SubnodePathfinder_pvt* pf)
return Iface_next(&pf->pub.eventIf, msg);
}
static Iface_DEFUN handlePong(Message_t* msg, struct SubnodePathfinder_pvt* pf)
static Iface_DEFUN handlePong(Gcc_UNUSED Message_t* msg, Gcc_UNUSED struct SubnodePathfinder_pvt* pf)
{
//Log_debug(pf->log, "Received pong");
return NULL;
}
@@ -566,12 +567,12 @@ void SubnodePathfinder_start(struct SubnodePathfinder* sp)
PingResponder_new(pf->alloc, pf->log, msgCore, pf->br, pf->myScheme);
struct ReachabilityCollector* rc = pf->pub.rc = ReachabilityCollector_new(
pf->alloc, msgCore, pf->log, pf->base, pf->br, pf->myAddress, pf->myScheme, pf->sp);
pf->alloc, msgCore, pf->log, pf->base, pf->br, pf->myAddress, pf->myScheme, pf->pub.sp);
rc->userData = pf;
rc->onChange = rcChange;
PeeringSeeder_t* ps = pf->pub.ps = PeeringSeeder_new(
pf->sp,
pf->pub.sp,
rc,
pf->alloc,
pf->log,
@@ -581,10 +582,10 @@ void SubnodePathfinder_start(struct SubnodePathfinder* sp)
Iface_plumb(ps->seederIface, &pf->seederIf);
struct SupernodeHunter* snh = pf->pub.snh = SupernodeHunter_new(
pf->alloc, pf->log, pf->base, pf->sp, pf->myPeerAddrs, msgCore, pf->myAddress, rc);
pf->alloc, pf->log, pf->base, pf->pub.sp, pf->myPeerAddrs, msgCore, pf->myAddress, rc);
pf->ra = ReachabilityAnnouncer_new(
pf->alloc, pf->log, pf->base, pf->rand, msgCore, snh, pf->privateKey, pf->myScheme, rc);
pf->alloc, pf->log, pf->base, pf->rand, msgCore, snh, pf->privateKey, pf->myScheme, rc, ps);
struct PFChan_Pathfinder_Connect conn = {
.superiority_be = Endian_hostToBigEndian32(1),
@@ -630,9 +631,9 @@ struct SubnodePathfinder* SubnodePathfinder_new(struct Allocator* allocator,
pf->myScheme = myScheme;
pf->br = BoilerplateResponder_new(myScheme, alloc);
pf->sp = SwitchPinger_new(base, rand, log, myAddress, alloc);
pf->pub.sp = SwitchPinger_new(base, rand, log, myAddress, alloc);
pf->switchPingerIf.send = ctrlMsgFromSwitchPinger;
Iface_plumb(&pf->switchPingerIf, &pf->sp->controlHandlerIf);
Iface_plumb(&pf->switchPingerIf, &pf->pub.sp->controlHandlerIf);
pf->seederIf.send = incomingFromSeeder;
pf->ca = ca;

View File

@@ -33,6 +33,7 @@ struct SubnodePathfinder
struct SupernodeHunter* snh;
struct ReachabilityCollector* rc;
PeeringSeeder_t* ps;
struct SwitchPinger* sp;
};
void SubnodePathfinder_start(struct SubnodePathfinder*);

View File

@@ -108,4 +108,6 @@ static inline void Gcc_checkPrintf(const char* format, ...)
// This does nothing except to trigger warnings if the format is wrong.
}
#define Gcc_UNUSED __attribute__((unused))
#endif