librats 0.5.2 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -106,7 +106,7 @@ std::vector<uint8_t> StunClient::create_binding_request() {
106
106
  std::mt19937 gen(rd());
107
107
  std::uniform_int_distribution<> dis(0, 255);
108
108
 
109
- for (int i = 0; i < stun::TRANSACTION_ID_SIZE; ++i) {
109
+ for (size_t i = 0; i < stun::TRANSACTION_ID_SIZE; ++i) {
110
110
  request[8 + i] = static_cast<uint8_t>(dis(gen));
111
111
  }
112
112
 
@@ -226,7 +226,7 @@ void StunClient::generate_transaction_id(uint8_t* transaction_id) {
226
226
  std::mt19937 gen(rd());
227
227
  std::uniform_int_distribution<> dis(0, 255);
228
228
 
229
- for (int i = 0; i < stun::TRANSACTION_ID_SIZE; ++i) {
229
+ for (size_t i = 0; i < stun::TRANSACTION_ID_SIZE; ++i) {
230
230
  transaction_id[i] = static_cast<uint8_t>(dis(gen));
231
231
  }
232
232
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "librats",
3
- "version": "0.5.2",
3
+ "version": "0.5.4",
4
4
  "description": "Node.js bindings for librats - A high-performance peer-to-peer networking library",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -190,7 +190,7 @@ public:
190
190
  return exports;
191
191
  }
192
192
 
193
- RatsClient(const Napi::CallbackInfo& info) : Napi::ObjectWrap<RatsClient>(info) {
193
+ RatsClient(const Napi::CallbackInfo& info) : Napi::ObjectWrap<RatsClient>(info), client_(nullptr) {
194
194
  Napi::Env env = info.Env();
195
195
 
196
196
  if (info.Length() < 1 || !info[0].IsNumber()) {
@@ -199,6 +199,10 @@ public:
199
199
  }
200
200
 
201
201
  int port = info[0].As<Napi::Number>().Int32Value();
202
+ if (port < 0 || port > 65535) {
203
+ Napi::RangeError::New(env, "Port number must be between 0 and 65535").ThrowAsJavaScriptException();
204
+ return;
205
+ }
202
206
  client_ = rats_create(port);
203
207
 
204
208
  if (!client_) {
@@ -208,7 +212,7 @@ public:
208
212
  }
209
213
 
210
214
  ~RatsClient() {
211
- if (client_) {
215
+ if (client_ != nullptr) {
212
216
  // Clean up callbacks
213
217
  connection_callbacks.erase(client_);
214
218
  string_callbacks.erase(client_);
@@ -232,7 +236,9 @@ private:
232
236
  }
233
237
 
234
238
  void Stop(const Napi::CallbackInfo& info) {
235
- rats_stop(client_);
239
+ if (client_ != nullptr) {
240
+ rats_stop(client_);
241
+ }
236
242
  }
237
243
 
238
244
  Napi::Value Connect(const Napi::CallbackInfo& info) {