sctp-socket 0.0.2 → 0.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3ac0fa4ee8107cb8b16e87b7313a8a14985ef78b01720fb1957240273e186536
4
- data.tar.gz: 926f171e90bcbdad7b1923490cf3cebe81448ef3610c30d77dacb46060f73f6b
3
+ metadata.gz: '0192244d6b63f84e1c1ed7eeca4a15e94a9f857bb932b2e246c929fa5d85a16c'
4
+ data.tar.gz: 61e37646cdb4138a8db5f43f9d8bbb9ade8094430b08a038f515edbb917b96be
5
5
  SHA512:
6
- metadata.gz: 57506b9decdc8652e085cc2bdb5b41167e9bb64b8ae4966856a44b208c83e2e2a0fadce33e6711223d3e2aeebabc70feef5ec85b2a66c906feb642323b646736
7
- data.tar.gz: 9d37cba691620fd8cc047da402a867c8ec60767fe5e05940a1a06d9ea1d2ac98e4dc9e52f2fb77c12c0485ac46f42aafcd0b8551147e3259850928b9fb80208d
6
+ metadata.gz: 06f2c3e32b6197647f22be5be5f6321167a9cc0db70035acf19522a9e27364d42c5b3511fd5958d7b27f09afad569ff5f679139d9d1c7c039ba5f23067272c49
7
+ data.tar.gz: 76326d271f9c36450698f8bafa4b63ce7167286814e09109c9a297f2bafec3ec0ecf7948970fd95c17ffb509be79dd934d8167f377e7dac6f504eeb908d331ba
Binary file
data.tar.gz.sig CHANGED
Binary file
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 1-Dec-2020
2
+ * Added notification hooks that you can subscribe to, so now the subscribe method
3
+ actually does something.
4
+
1
5
  ## 29-Nov-2020
2
6
  * Fixed the homepage link in the gemspec metadata. Thanks go to Nick LaMuro for the patch.
3
7
  * The getlocalnames and getpeernames now return an array of addresses.
data/README.md CHANGED
@@ -53,8 +53,9 @@ end
53
53
 
54
54
  ## Future Plans
55
55
 
56
- * Check for notification data and return it if encountered.
57
- * Add specs.
56
+ * Add more constants.
57
+ * Add more specs.
58
+ * Add more notifications.
58
59
 
59
60
  ## Known Issues
60
61
 
@@ -7,6 +7,15 @@
7
7
  VALUE mSCTP;
8
8
  VALUE cSocket;
9
9
  VALUE v_sndrcv_struct;
10
+ VALUE v_assoc_change_struct;
11
+ VALUE v_peeraddr_change_struct;
12
+ VALUE v_remote_error_struct;
13
+ VALUE v_send_failed_event_struct;
14
+ VALUE v_shutdown_event_struct;
15
+ VALUE v_sndinfo_struct;
16
+ VALUE v_adaptation_event_struct;
17
+ VALUE v_partial_delivery_event_struct;
18
+ VALUE v_auth_event_struct;
10
19
 
11
20
  // Helper function to get a hash value via string or symbol.
12
21
  VALUE rb_hash_aref2(VALUE v_hash, const char* key){
@@ -425,7 +434,7 @@ static VALUE rsctp_sendmsg(VALUE self, VALUE v_options){
425
434
  * end
426
435
  */
427
436
  static VALUE rsctp_recvmsg(int argc, VALUE* argv, VALUE self){
428
- VALUE v_flags;
437
+ VALUE v_flags, v_notification, v_message;
429
438
  struct sctp_sndrcvinfo sndrcvinfo;
430
439
  struct sockaddr_in clientaddr;
431
440
  int flags, bytes, sock_fd;
@@ -456,39 +465,176 @@ static VALUE rsctp_recvmsg(int argc, VALUE* argv, VALUE self){
456
465
  if(bytes < 0)
457
466
  rb_raise(rb_eSystemCallError, "sctp_recvmsg: %s", strerror(errno));
458
467
 
459
- // TODO: Check for MSG_NOTIFICATION, return different structs for events.
460
- /*
468
+ v_notification = Qnil;
469
+
461
470
  if(flags & MSG_NOTIFICATION){
471
+ uint32_t i;
472
+ char str[16];
462
473
  union sctp_notification* snp;
474
+ VALUE v_str;
475
+ VALUE* v_temp;
476
+
463
477
  snp = (union sctp_notification*)buffer;
464
478
 
465
- switch(snp->sn_type){
479
+ switch(snp->sn_header.sn_type){
466
480
  case SCTP_ASSOC_CHANGE:
481
+ switch(snp->sn_assoc_change.sac_state){
482
+ case SCTP_COMM_LOST:
483
+ v_str = rb_str_new2("comm lost");
484
+ break;
485
+ case SCTP_COMM_UP:
486
+ v_str = rb_str_new2("comm up");
487
+ break;
488
+ case SCTP_RESTART:
489
+ v_str = rb_str_new2("restart");
490
+ break;
491
+ case SCTP_SHUTDOWN_COMP:
492
+ v_str = rb_str_new2("shutdown complete");
493
+ break;
494
+ case SCTP_CANT_STR_ASSOC:
495
+ v_str = rb_str_new2("association setup failed");
496
+ break;
497
+ default:
498
+ v_str = rb_str_new2("unknown");
499
+ }
500
+
501
+ v_notification = rb_struct_new(v_assoc_change_struct,
502
+ UINT2NUM(snp->sn_assoc_change.sac_type),
503
+ UINT2NUM(snp->sn_assoc_change.sac_length),
504
+ UINT2NUM(snp->sn_assoc_change.sac_state),
505
+ UINT2NUM(snp->sn_assoc_change.sac_error),
506
+ UINT2NUM(snp->sn_assoc_change.sac_outbound_streams),
507
+ UINT2NUM(snp->sn_assoc_change.sac_inbound_streams),
508
+ UINT2NUM(snp->sn_assoc_change.sac_assoc_id),
509
+ v_str
510
+ );
467
511
  break;
468
512
  case SCTP_PEER_ADDR_CHANGE:
513
+ switch(snp->sn_paddr_change.spc_state){
514
+ case SCTP_ADDR_AVAILABLE:
515
+ v_str = rb_str_new2("available");
516
+ break;
517
+ case SCTP_ADDR_UNREACHABLE:
518
+ v_str = rb_str_new2("unreachable");
519
+ break;
520
+ case SCTP_ADDR_REMOVED:
521
+ v_str = rb_str_new2("removed from association");
522
+ break;
523
+ case SCTP_ADDR_ADDED:
524
+ v_str = rb_str_new2("added to association");
525
+ break;
526
+ case SCTP_ADDR_MADE_PRIM:
527
+ v_str = rb_str_new2("primary destination");
528
+ break;
529
+ default:
530
+ v_str = rb_str_new2("unknown");
531
+ }
532
+
533
+ inet_ntop(
534
+ ((struct sockaddr_in *)&snp->sn_paddr_change.spc_aaddr)->sin_family,
535
+ &(((struct sockaddr_in *)&snp->sn_paddr_change.spc_aaddr)->sin_addr),
536
+ str,
537
+ sizeof(str)
538
+ );
539
+
540
+ v_notification = rb_struct_new(v_peeraddr_change_struct,
541
+ UINT2NUM(snp->sn_paddr_change.spc_type),
542
+ UINT2NUM(snp->sn_paddr_change.spc_length),
543
+ rb_str_new2(str),
544
+ UINT2NUM(snp->sn_paddr_change.spc_state),
545
+ UINT2NUM(snp->sn_paddr_change.spc_error),
546
+ UINT2NUM(snp->sn_paddr_change.spc_assoc_id),
547
+ v_str
548
+ );
469
549
  break;
470
550
  case SCTP_REMOTE_ERROR:
551
+ v_temp = ALLOCA_N(VALUE, snp->sn_remote_error.sre_length);
552
+
553
+ for(i = 0; i < snp->sn_remote_error.sre_length; i++){
554
+ v_temp[i] = UINT2NUM(snp->sn_remote_error.sre_data[i]);
555
+ }
556
+
557
+ v_notification = rb_struct_new(v_remote_error_struct,
558
+ UINT2NUM(snp->sn_remote_error.sre_type),
559
+ UINT2NUM(snp->sn_remote_error.sre_length),
560
+ UINT2NUM(snp->sn_remote_error.sre_error),
561
+ UINT2NUM(snp->sn_remote_error.sre_assoc_id),
562
+ rb_ary_new4(snp->sn_remote_error.sre_length, v_temp)
563
+ );
471
564
  break;
472
- case SCTP_SEND_FAILED:
565
+ case SCTP_SEND_FAILED_EVENT:
566
+ v_temp = ALLOCA_N(VALUE, snp->sn_send_failed_event.ssf_length);
567
+
568
+ for(i = 0; i < snp->sn_send_failed_event.ssf_length; i++){
569
+ v_temp[i] = UINT2NUM(snp->sn_send_failed_event.ssf_data[i]);
570
+ }
571
+
572
+ v_notification = rb_struct_new(v_send_failed_event_struct,
573
+ UINT2NUM(snp->sn_send_failed_event.ssf_type),
574
+ UINT2NUM(snp->sn_send_failed_event.ssf_length),
575
+ UINT2NUM(snp->sn_send_failed_event.ssf_error),
576
+ rb_struct_new(v_sndinfo_struct,
577
+ UINT2NUM(snp->sn_send_failed_event.ssfe_info.snd_sid),
578
+ UINT2NUM(snp->sn_send_failed_event.ssfe_info.snd_flags),
579
+ UINT2NUM(snp->sn_send_failed_event.ssfe_info.snd_ppid),
580
+ UINT2NUM(snp->sn_send_failed_event.ssfe_info.snd_context),
581
+ UINT2NUM(snp->sn_send_failed_event.ssfe_info.snd_assoc_id)
582
+ ),
583
+ UINT2NUM(snp->sn_send_failed_event.ssf_assoc_id),
584
+ rb_ary_new4(snp->sn_send_failed_event.ssf_length, v_temp)
585
+ );
473
586
  break;
474
587
  case SCTP_SHUTDOWN_EVENT:
588
+ v_notification = rb_struct_new(v_shutdown_event_struct,
589
+ UINT2NUM(snp->sn_shutdown_event.sse_type),
590
+ UINT2NUM(snp->sn_shutdown_event.sse_length),
591
+ UINT2NUM(snp->sn_shutdown_event.sse_assoc_id)
592
+ );
475
593
  break;
476
594
  case SCTP_ADAPTATION_INDICATION:
595
+ v_notification = rb_struct_new(v_adaptation_event_struct,
596
+ UINT2NUM(snp->sn_adaptation_event.sai_type),
597
+ UINT2NUM(snp->sn_adaptation_event.sai_length),
598
+ UINT2NUM(snp->sn_adaptation_event.sai_adaptation_ind),
599
+ UINT2NUM(snp->sn_adaptation_event.sai_assoc_id)
600
+ );
477
601
  break;
478
602
  case SCTP_PARTIAL_DELIVERY_EVENT:
603
+ v_notification = rb_struct_new(v_partial_delivery_event_struct,
604
+ UINT2NUM(snp->sn_pdapi_event.pdapi_type),
605
+ UINT2NUM(snp->sn_pdapi_event.pdapi_length),
606
+ UINT2NUM(snp->sn_pdapi_event.pdapi_indication),
607
+ UINT2NUM(snp->sn_pdapi_event.pdapi_stream),
608
+ UINT2NUM(snp->sn_pdapi_event.pdapi_seq),
609
+ UINT2NUM(snp->sn_pdapi_event.pdapi_assoc_id)
610
+ );
611
+ break;
612
+ case SCTP_AUTHENTICATION_EVENT:
613
+ v_notification = rb_struct_new(v_auth_event_struct,
614
+ UINT2NUM(snp->sn_authkey_event.auth_type),
615
+ UINT2NUM(snp->sn_authkey_event.auth_length),
616
+ UINT2NUM(snp->sn_authkey_event.auth_keynumber),
617
+ UINT2NUM(snp->sn_authkey_event.auth_indication),
618
+ UINT2NUM(snp->sn_authkey_event.auth_assoc_id)
619
+ );
479
620
  break;
480
621
  }
481
622
  }
482
- */
623
+
624
+ if(NIL_P(v_notification))
625
+ v_message = rb_str_new(buffer, bytes);
626
+ else
627
+ v_message = Qnil;
483
628
 
484
629
  return rb_struct_new(v_sndrcv_struct,
485
- rb_str_new(buffer, bytes),
630
+ v_message,
486
631
  UINT2NUM(sndrcvinfo.sinfo_stream),
487
632
  UINT2NUM(sndrcvinfo.sinfo_flags),
488
633
  UINT2NUM(sndrcvinfo.sinfo_ppid),
489
634
  UINT2NUM(sndrcvinfo.sinfo_context),
490
635
  UINT2NUM(sndrcvinfo.sinfo_timetolive),
491
- UINT2NUM(sndrcvinfo.sinfo_assoc_id)
636
+ UINT2NUM(sndrcvinfo.sinfo_assoc_id),
637
+ v_notification
492
638
  );
493
639
  }
494
640
 
@@ -558,14 +704,19 @@ static VALUE rsctp_set_initmsg(VALUE self, VALUE v_options){
558
704
  * :shutdown
559
705
  * - The peer has sent a shutdown to the local endpoint.
560
706
  *
707
+ * :data_io
708
+ * - Message data was received. On by default.
709
+ *
561
710
  * Others:
562
711
  *
563
- * :adaptation_layer
564
- * :authentication_event
565
- * :data_io
566
- * :peer_error
712
+ * :adaptation
713
+ * :authentication
567
714
  * :partial_delivery
715
+ *
716
+ * Not yet supported:
717
+ *
568
718
  * :sender_dry
719
+ * :peer_error
569
720
  *
570
721
  * By default only data_io is subscribed to.
571
722
  *
@@ -592,8 +743,9 @@ static VALUE rsctp_subscribe(VALUE self, VALUE v_options){
592
743
  if(RTEST(rb_hash_aref2(v_options, "address")))
593
744
  events.sctp_address_event = 1;
594
745
 
746
+ // Use the new version
595
747
  if(RTEST(rb_hash_aref2(v_options, "send_failure")))
596
- events.sctp_send_failure_event = 1;
748
+ events.sctp_send_failure_event_event = 1;
597
749
 
598
750
  if(RTEST(rb_hash_aref2(v_options, "peer_error")))
599
751
  events.sctp_peer_error_event = 1;
@@ -700,8 +852,47 @@ void Init_socket(){
700
852
  cSocket = rb_define_class_under(mSCTP, "Socket", rb_cObject);
701
853
 
702
854
  v_sndrcv_struct = rb_struct_define(
703
- "SndRecvInfo", "message", "stream", "flags",
704
- "ppid", "context", "ttl", "association_id", NULL
855
+ "SendReceiveInfo", "message", "stream", "flags",
856
+ "ppid", "context", "ttl", "association_id", "notification", NULL
857
+ );
858
+
859
+ v_assoc_change_struct = rb_struct_define(
860
+ "AssocChange", "type", "length", "state", "error",
861
+ "outbound_streams", "inbound_streams", "association_id", "info", NULL
862
+ );
863
+
864
+ v_peeraddr_change_struct = rb_struct_define(
865
+ "PeerAddrChange", "type", "length", "ip_address",
866
+ "state", "error", "association_id", "info", NULL
867
+ );
868
+
869
+ v_remote_error_struct = rb_struct_define(
870
+ "RemoteError", "type", "length", "error", "association_id", "data", NULL
871
+ );
872
+
873
+ v_send_failed_event_struct = rb_struct_define(
874
+ "SendFailedEvent", "type", "length", "error", "association_id", "data", NULL
875
+ );
876
+
877
+ v_shutdown_event_struct = rb_struct_define(
878
+ "ShutdownEvent", "type", "length", "association_id", NULL
879
+ );
880
+
881
+ v_sndinfo_struct = rb_struct_define(
882
+ "SendInfo", "sid", "flags", "ppid", "context", "association_id", NULL
883
+ );
884
+
885
+ v_adaptation_event_struct = rb_struct_define(
886
+ "AdaptationEvent", "type", "length", "adaptation_indication", "association_id", NULL
887
+ );
888
+
889
+ v_partial_delivery_event_struct = rb_struct_define(
890
+ "PartialDeliveryEvent", "type", "length", "indication", "stream",
891
+ "sequence_number", "association_id", NULL
892
+ );
893
+
894
+ v_auth_event_struct = rb_struct_define(
895
+ "AuthEvent", "type", "length", "key_number", "indication", "association_id", NULL
705
896
  );
706
897
 
707
898
  rb_define_method(cSocket, "initialize", rsctp_init, -1);
@@ -726,5 +917,5 @@ void Init_socket(){
726
917
  rb_define_attr(cSocket, "port", 1, 1);
727
918
 
728
919
  /* 0.0.2: The version of this library */
729
- rb_define_const(cSocket, "VERSION", rb_str_new2("0.0.2"));
920
+ rb_define_const(cSocket, "VERSION", rb_str_new2("0.0.3"));
730
921
  }
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'sctp-socket'
3
- spec.version = '0.0.2'
3
+ spec.version = '0.0.3'
4
4
  spec.author = 'Daniel Berger'
5
5
  spec.email = 'djberg96@gmail.com'
6
6
  spec.summary = 'Ruby bindings for SCTP sockets'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sctp-socket
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Berger
@@ -35,7 +35,7 @@ cert_chain:
35
35
  ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
36
36
  WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
37
37
  -----END CERTIFICATE-----
38
- date: 2020-11-29 00:00:00.000000000 Z
38
+ date: 2020-12-01 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: bundler
metadata.gz.sig CHANGED
Binary file