Unable to add / remove peers #7

Closed
opened 2024-02-19 16:59:50 +00:00 by MorningLightMountain713 · 6 comments

Hi there,

I don't seem to be able to modify any config.

Everything works fine if the interface doesn't exist.

However, I want to add / remove peers once the interface has been created. This is how I would expect to add a peer, but it doesn't work. (I figure if I leave replace peers out, it should just add a peer)

import { wginterface } from "wireguard-tools.js";

const newConf: wginterface.WgConfig = {
  peers: {
    "QVa3K2swzHsmN3PmuoeEppv7m7J9vlXGPL5FkrAecFM=": {
      keepInterval: 25,
      endpoint: "x.x.x.x:51003",
      allowedIPs: ["172.23.46.0/24", "10.10.9.3/32"],
    }
  },
};
await wginterface.setConfig("wg0", newConf);

/home/davew/netlink/node_modules/wireguard-tools.js/src/wginterface.js:47
	return addon.setConfig(wgName, config);
	             ^

Error: privateKey is empty

If I then add privatekey etc, it tries to add the interface again

node:internal/process/esm_loader:40
      internalBinding('errors').triggerUncaughtException(
                                ^

[Error: Cannot add device, code: -17]
Hi there, I don't seem to be able to modify any config. Everything works fine if the interface doesn't exist. However, I want to add / remove peers once the interface has been created. This is how I would expect to add a peer, but it doesn't work. (I figure if I leave replace peers out, it should just add a peer) ```javascript import { wginterface } from "wireguard-tools.js"; const newConf: wginterface.WgConfig = { peers: { "QVa3K2swzHsmN3PmuoeEppv7m7J9vlXGPL5FkrAecFM=": { keepInterval: 25, endpoint: "x.x.x.x:51003", allowedIPs: ["172.23.46.0/24", "10.10.9.3/32"], } }, }; await wginterface.setConfig("wg0", newConf); ``` ``` /home/davew/netlink/node_modules/wireguard-tools.js/src/wginterface.js:47 return addon.setConfig(wgName, config); ^ Error: privateKey is empty ``` If I then add privatekey etc, it tries to add the interface again ``` node:internal/process/esm_loader:40 internalBinding('errors').triggerUncaughtException( ^ [Error: Cannot add device, code: -17] ```

get config and set a new peer, to remove set removeMe in peer options.

import { wginterface } from "wireguard-tools.js";

const config = await wginterface.getConfig("wg0") as any as WgConfigSet;

// Set new Peer from existing interface
config.peers["QVa3K2swzHsmN3PmuoeEppv7m7J9vlXGPL5FkrAecFM="] = {
      keepInterval: 25,
      endpoint: "x.x.x.x:51003",
      allowedIPs: ["172.23.46.0/24", "10.10.9.3/32"]
};

// To remove
config.peers["QVa3K2swzHsmN3PmuoeEppv7m7J9vlXGPL5FkrAecFM="].removeMe = true;

await wginterface.setConfig("wg0", config);
get config and set a new peer, to remove set `removeMe` in peer options. ```ts import { wginterface } from "wireguard-tools.js"; const config = await wginterface.getConfig("wg0") as any as WgConfigSet; // Set new Peer from existing interface config.peers["QVa3K2swzHsmN3PmuoeEppv7m7J9vlXGPL5FkrAecFM="] = { keepInterval: 25, endpoint: "x.x.x.x:51003", allowedIPs: ["172.23.46.0/24", "10.10.9.3/32"] }; // To remove config.peers["QVa3K2swzHsmN3PmuoeEppv7m7J9vlXGPL5FkrAecFM="].removeMe = true; await wginterface.setConfig("wg0", config); ```

This is an addon error in which it does not find the interface and tries to create a new one, an error that went unnoticed by me

If I then add privatekey etc, it tries to add the interface again

node:internal/process/esm_loader:40
      internalBinding('errors').triggerUncaughtException(
                                ^

[Error: Cannot add device, code: -17]
This is an addon error in which it does not find the interface and tries to create a new one, an error that went unnoticed by me > If I then add privatekey etc, it tries to add the interface again > > ``` > node:internal/process/esm_loader:40 > internalBinding('errors').triggerUncaughtException( > ^ > > [Error: Cannot add device, code: -17] > ```
Sirherobrine23 pinned this 2024-02-19 17:19:03 +00:00
Sirherobrine23 added the
Kind/Bug
Kind/Enhancement
Kind/Documentation
Priority
High
labels 2024-02-19 17:19:28 +00:00

@MorningLightMountain713 In this commit [b8b39f4a2f] i fixed this message and correctly set Wireguard configurations, the fix Will be releasing in the next tag (npm i wireguard-tools.js@next) soon

@MorningLightMountain713 In this commit [b8b39f4a2f01b3752d259a8739a22b1a47107697] i fixed this message and correctly set Wireguard configurations, the fix Will be releasing in the next tag (`npm i wireguard-tools.js@next`) soon

@MorningLightMountain713 In this commit [b8b39f4a2f] i fixed this message and correctly set Wireguard configurations, the fix Will be releasing in the next tag (npm i wireguard-tools.js@next) soon

Thats great! Thanks for the quick fix!

> @MorningLightMountain713 In this commit [b8b39f4a2f01b3752d259a8739a22b1a47107697] i fixed this message and correctly set Wireguard configurations, the fix Will be releasing in the next tag (`npm i wireguard-tools.js@next`) soon Thats great! Thanks for the quick fix!

I'm changing the wg.js compiler, so it's easy to make quick changes.

I'm changing the wg.js compiler, so it's easy to make quick changes.
Sirherobrine23 unpinned this 2024-02-20 15:58:27 +00:00

wireguard-tools.js@2.0.0 is published 🎉

npm publish --access public --tag next
npm notice 
npm notice 📦  wireguard-tools.js@2.0.0
npm notice === Tarball Contents === 
npm notice 35.2kB  LICENSE                                              
npm notice 1.3kB   README.md                                            
npm notice 5.3kB   addons/genKey/key_gen.cpp                            
npm notice 8.1kB   addons/genKey/wgkeys.cpp                             
npm notice 766B    addons/genKey/wgkeys.hh                              
npm notice 120B    addons/tools/linux/set_ip.cpp                        
npm notice 43.7kB  addons/tools/linux/wireguard.c                       
npm notice 2.9kB   addons/tools/linux/wireguard.h                       
npm notice 264B    addons/tools/wginterface-dummy.cpp                   
npm notice 18.7kB  addons/tools/wginterface-linux.cpp                   
npm notice 16.9kB  addons/tools/wginterface-win.cpp                     
npm notice 4.3kB   addons/tools/wginterface.cpp                         
npm notice 11.8kB  addons/tools/wginterface.hh                          
npm notice 6.4kB   addons/tools/win/shared.cpp                          
npm notice 1.3MB   addons/tools/win/wireguard-nt/bin/amd64/wireguard.dll
npm notice 669.8kB addons/tools/win/wireguard-nt/bin/arm64/wireguard.dll
npm notice 12.3kB  addons/tools/win/wireguard-nt/include/wireguard.h    
npm notice 5.4kB   addons/tools/win/wireguard-nt/LICENSE.txt            
npm notice 16.9kB  addons/tools/win/wireguard-nt/README.md              
npm notice 1.6kB   binding.yaml                                         
npm notice 3.6MB   build/linux/aarch64/Release/wginterface.node         
npm notice 3.5MB   build/linux/x86_64/Release/wginterface.node          
npm notice 1.2MB   build/windows/aarch64/Release/wginterface.node       
npm notice 1.2MB   build/windows/x86_64/Release/wginterface.node        
npm notice 1.4kB   package.json                                         
npm notice 50B     src/index_test.d.ts                                  
npm notice 200B    src/index.d.ts                                       
npm notice 200B    src/index.js                                         
npm notice 11B     src/key_test.d.ts                                    
npm notice 704B    src/key.d.ts                                         
npm notice 4.3kB   src/key.js                                           
npm notice 11B     src/quick_test.d.ts                                  
npm notice 592B    src/quick.d.ts                                       
npm notice 5.8kB   src/quick.js                                         
npm notice 2.7kB   src/wginterface.d.ts                                 
npm notice 8.5kB   src/wginterface.js                                   
npm notice 621B    tsconfig.json                                        
npm notice === Tarball Details === 
npm notice name:          wireguard-tools.js                      
npm notice version:       2.0.0                                   
npm notice filename:      wireguard-tools.js-2.0.0.tgz            
npm notice package size:  3.3 MB                                  
npm notice unpacked size: 11.7 MB                                 
npm notice shasum:        41934d30b01c095254a079d4f262f7e1f6bad7dd
npm notice integrity:     sha512-P7V3lkzCr9bIf[...]MInUfgCxqkJHA==
npm notice total files:   37                                      
npm notice 
npm notice Publishing to https://registry.npmjs.org/ with tag next and public access

+ wireguard-tools.js@2.0.0
`wireguard-tools.js@2.0.0` is published 🎉 ``` npm publish --access public --tag next npm notice npm notice 📦 wireguard-tools.js@2.0.0 npm notice === Tarball Contents === npm notice 35.2kB LICENSE npm notice 1.3kB README.md npm notice 5.3kB addons/genKey/key_gen.cpp npm notice 8.1kB addons/genKey/wgkeys.cpp npm notice 766B addons/genKey/wgkeys.hh npm notice 120B addons/tools/linux/set_ip.cpp npm notice 43.7kB addons/tools/linux/wireguard.c npm notice 2.9kB addons/tools/linux/wireguard.h npm notice 264B addons/tools/wginterface-dummy.cpp npm notice 18.7kB addons/tools/wginterface-linux.cpp npm notice 16.9kB addons/tools/wginterface-win.cpp npm notice 4.3kB addons/tools/wginterface.cpp npm notice 11.8kB addons/tools/wginterface.hh npm notice 6.4kB addons/tools/win/shared.cpp npm notice 1.3MB addons/tools/win/wireguard-nt/bin/amd64/wireguard.dll npm notice 669.8kB addons/tools/win/wireguard-nt/bin/arm64/wireguard.dll npm notice 12.3kB addons/tools/win/wireguard-nt/include/wireguard.h npm notice 5.4kB addons/tools/win/wireguard-nt/LICENSE.txt npm notice 16.9kB addons/tools/win/wireguard-nt/README.md npm notice 1.6kB binding.yaml npm notice 3.6MB build/linux/aarch64/Release/wginterface.node npm notice 3.5MB build/linux/x86_64/Release/wginterface.node npm notice 1.2MB build/windows/aarch64/Release/wginterface.node npm notice 1.2MB build/windows/x86_64/Release/wginterface.node npm notice 1.4kB package.json npm notice 50B src/index_test.d.ts npm notice 200B src/index.d.ts npm notice 200B src/index.js npm notice 11B src/key_test.d.ts npm notice 704B src/key.d.ts npm notice 4.3kB src/key.js npm notice 11B src/quick_test.d.ts npm notice 592B src/quick.d.ts npm notice 5.8kB src/quick.js npm notice 2.7kB src/wginterface.d.ts npm notice 8.5kB src/wginterface.js npm notice 621B tsconfig.json npm notice === Tarball Details === npm notice name: wireguard-tools.js npm notice version: 2.0.0 npm notice filename: wireguard-tools.js-2.0.0.tgz npm notice package size: 3.3 MB npm notice unpacked size: 11.7 MB npm notice shasum: 41934d30b01c095254a079d4f262f7e1f6bad7dd npm notice integrity: sha512-P7V3lkzCr9bIf[...]MInUfgCxqkJHA== npm notice total files: 37 npm notice npm notice Publishing to https://registry.npmjs.org/ with tag next and public access + wireguard-tools.js@2.0.0 ```
Sign in to join this conversation.
No description provided.