Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
bf5ea8d
Remove old nuclear subtree before NUClearNet 2 import
TrentHouliston Jun 3, 2026
4f210c0
Squashed 'src/nuclear/' content from commit ce389fbf
TrentHouliston Jun 3, 2026
0623a32
Update nuclear subtree for NUClearNet 2 (NUClear PR #190)
TrentHouliston Jun 3, 2026
d980d90
Update Node binding and JS API for NUClearNet 2
TrentHouliston Jun 3, 2026
5713844
Fix CI: Windows WSABUF build, skip macOS multicast tests in CI
TrentHouliston Jun 3, 2026
1b1d20a
Fix remaining Windows iovec and sendmsg build errors in NUClearNet
TrentHouliston Jun 3, 2026
602da00
Add tiered debug logging for NUClearNet 2
TrentHouliston Jun 3, 2026
b4a07f5
Sync nuclear subtree: upstream logging, rebind, and Windows fixes
TrentHouliston Jun 3, 2026
0ce3960
Sync nuclear subtree from NUClear@2441bdf
TrentHouliston Jun 3, 2026
dca27a2
Update README NUClear subtree pin to 2441bdf
TrentHouliston Jun 3, 2026
e09d45a
Fix self-announce filtering, resolve iteration, and multicast loop
TrentHouliston Jun 17, 2026
2c71eb1
Restart NetworkListener on socket rebind and reset
TrentHouliston Jun 17, 2026
f9b70fe
Parameterize network tests for multicast and loopback modes
TrentHouliston Jun 17, 2026
b7932f2
Update README NUClear subtree pin to 18c2877b
TrentHouliston Jun 17, 2026
ea8550a
Send the native NUClearNet logs to the JavaScript logger
Aug 14, 2026
e0aa452
Sync nuclear subtree from NUClear@c6194028
Aug 14, 2026
e90cc31
Sync nuclear subtree from NUClear@ffd7231c
Aug 14, 2026
1243bb7
Sync nuclear subtree from NUClear@62bc83a1
Aug 14, 2026
e3bea85
Sync nuclear subtree from NUClear@2053a375
Aug 14, 2026
002fcbe
Sync nuclear subtree from NUClear@e689ffdb
Aug 14, 2026
7f98a53
Sync nuclear subtree from NUClear@92711931
Aug 14, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
build
.git
.github
16 changes: 16 additions & 0 deletions .github/workflows/docker-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Docker Linux test

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Build and test in Docker
run: docker build -t nuclearnet.js-test .
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM node:20-bookworm

RUN apt-get update \
&& apt-get install -y --no-install-recommends python3 make g++ \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /app

COPY package.json package-lock.json ./
RUN npm ci

COPY . .

RUN npm run build
CMD ["npm", "test"]
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@

Node.js module for interacting with the [NUClear](https://github.com/Fastcode/NUClear) network.

## NUClearNet 2 (v2.0.0+)

Version 2 uses the redesigned **NUClearNet** library from [NUClear PR #190](https://github.com/Fastcode/NUClear/pull/190) (wire protocol **0x03**). It is **not** compatible with 1.x clients or NUClear builds that still use the old `NUClearNetwork` stack (protocol 0x02). Upgrade Node clients and NUClear robots together.

The vendored NUClear tree is updated via `git subtree` from the `houliston/nuclearnet-v2` branch (currently [NUClear@92711931](https://github.com/Fastcode/NUClear/commit/92711931)).

Peer join events may arrive slightly later than in 1.x because connection requires both multicast announce and a unicast CONNECT handshake.

## Installation

The package contains a native module, so you'll need a working C++ compiler on your system to install and build it.
Expand Down Expand Up @@ -57,6 +65,25 @@ net.on('packet_type_a', function (packet) {
net.connect({ name: 'My Name' });
```

## Debugging

Logging is off by default. Enable tiered logs with `connect({ debug: ... })`, the constructor default, or the `NUCLEARNET_DEBUG` environment variable (`connect` wins when both are set).

| Level | JavaScript | Native (stderr) |
| ----- | ---------- | ----------------- |
| `info` | connect, join, leave, subscriptions | reset, shutdown, peer timeouts |
| `debug` | send, packets, listener subscribe/unsubscribe | handshake, announce/connect, send routing |
| `trace` | process wait scheduling | `process()` ticks, socket reads |

```js
const net = new NUClearNet({ debug: 'info' });
net.connect({ name: 'node-1', debug: 'debug' }); // overrides constructor for this session
```

```bash
NUCLEARNET_DEBUG=info node your-app.js
```

## API

See [`index.d.ts`](./index.d.ts) for types and API details.
22 changes: 16 additions & 6 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,22 @@
'src/binding.cpp',
'src/NetworkBinding.cpp',
'src/NetworkListener.cpp',
'src/nuclear/src/extension/network/NUClearNetwork.cpp',
'src/nuclear/src/util/platform.cpp',
'src/nuclear/src/util/network/get_interfaces.cpp',
'src/nuclear/src/util/network/if_number_from_address.cpp',
'src/nuclear/src/nuclearnet/Discovery.cpp',
'src/nuclear/src/nuclearnet/Log.cpp',
'src/nuclear/src/nuclearnet/Fragmentation.cpp',
'src/nuclear/src/nuclearnet/NUClearNet.cpp',
'src/nuclear/src/nuclearnet/PacketDeduplicator.cpp',
'src/nuclear/src/nuclearnet/RTTEstimator.cpp',
'src/nuclear/src/nuclearnet/Reliability.cpp',
'src/nuclear/src/nuclearnet/Routing.cpp',
'src/nuclear/src/util/network/resolve.cpp',
'src/nuclear/src/util/platform.cpp',
'src/nuclear/src/util/serialise/xxhash.cpp'
],
'cflags': [],
'include_dirs': [
'<!@(node -p "require(\'node-addon-api\').include")',
'src/nuclear/src/include'
'src/nuclear/src'
],
"defines": [
# Restrict NAPI to v6 (to support Node v10)
Expand Down Expand Up @@ -82,7 +87,12 @@
],
[
'OS=="win"', {
'defines': [ '_HAS_EXCEPTIONS=1' ]
'defines': [ '_HAS_EXCEPTIONS=1' ],
'libraries': [
'ws2_32.lib',
'mswsock.lib',
'iphlpapi.lib'
]
}
]
]
Expand Down
14 changes: 12 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ export interface NUClearNetOptions {

/** The MTU of the network. Used for splitting packets optimally. */
mtu?: number;

/**
* Enable debug logging. `true` is equivalent to `info`.
* Logs from the native library and from JavaScript both use `console.error` with a `[NUClearNet.js]` prefix.
* The `NUCLEARNET_DEBUG` environment variable applies when this option is omitted.
*/
debug?: boolean | 'off' | 'error' | 'warn' | 'info' | 'debug' | 'trace';
}

/**
Expand Down Expand Up @@ -131,8 +138,11 @@ export declare class NUClearNet {
/** Stores the `connect()` options. Is an empty object until `connect()` is called. */
options: Partial<NUClearNetOptions>;

/** Create a new NUClearNet instance. */
public constructor();
/**
* Create a new NUClearNet instance.
* @param options Optional default `debug` level (overridden by `connect({ debug })`).
*/
public constructor(options?: { debug?: NUClearNetOptions['debug'] });

/** Emitted when a peer joins or leaves the network. */
public on(event: 'nuclear_join' | 'nuclear_leave', callback: (peer: NUClearNetPeer) => void): this;
Expand Down
Loading
Loading