Browse code

Add p2p calls

Jaidyn Levesque authored on 2019-06-18 17:03:08
Showing 2 changed files
... ...
@@ -780,6 +780,77 @@
780 780
 
781 781
 
782 782
 
783
+;; —————————————————————————————————————
784
+;; P2P CALLS
785
+
786
+;; [:BOOLEAN :STRING :STRING :STRING :STRING] → NUMBER || (NIL STRING)
787
+(defun p2p-close (&key (all "") (protocol nil) (listen-address nil)
788
+		       (target-address nil))
789
+  "Stop listening for new connections to forward.
790
+  /ipns/docs.ipfs.io/reference/api/http/#api-v0-p2p-close"
791
+  (bind-api-result
792
+    (ipfs-call "p2p/close" `(,(when (not (empty-string-p all)) `("all" ,all))
793
+			      ,(when protocol `("protocol" ,protocol))
794
+			      ,(when listen-address
795
+				 `("listen-address" ,listen-address))
796
+			      ,(when target-address
797
+				 `("target-address" ,target-address))))
798
+    result))
799
+
800
+;; STRING STRING STRING [:BOOLEAN] → STRING || (NIL STRING)
801
+(defun p2p-forward (protocol listening-endpoint target-endpoint
802
+			     &key (allow-custom-protocol ""))
803
+  "Forward connections to libp2p service.
804
+  /ipns/docs.ipfs.io/reference/api/http/#api-v0-p2p-forward"
805
+  (bind-api-result
806
+    (ipfs-call "p2p/forward" `(("arg" ,protocol)("arg" ,listening-endpoint)
807
+			       ("arg" ,target-endpoint)
808
+			       ,(when
809
+				  (not (empty-string-p allow-custom-protocol))
810
+				  `("allow-custom-protocol"
811
+				    ,allow-custom-protocol))))
812
+    result))
813
+
814
+;; STRING STRING [:BOOLEAN :BOOLEAN] → STRING || (NIL STRING)
815
+(defun p2p-listen (protocol target-endpoint
816
+			    &key (allow-custom-protocol "") (report-peer-id ""))
817
+  "Create libp2p service.
818
+  /ipns/docs.ipfs.io/reference/api/http/#api-v0-p2p-listen"
819
+  (bind-api-result
820
+    (ipfs-call "p2p/listen" `(("arg" ,protocol)("arg" ,target-endpoint)
821
+			       ,(when
822
+				  (not (empty-string-p allow-custom-protocol))
823
+				  `("allow-custom-protocol"
824
+				    ,allow-custom-protocol))
825
+			       ,(when (not (empty-string-p report-peer-id))
826
+				  `("report-peer-id" ,report-peer-id))))
827
+    result))
828
+
829
+;; NIL → ALIST || (NIL STRING)
830
+(defun p2p-ls ()
831
+  "List active p2p listeners.
832
+  /ipns/docs.ipfs.io/reference/api/http/#api-v0-p2p-ls"
833
+  (bind-api-alist (ipfs-call "p2p/ls" '())))
834
+
835
+;; [:STRING :BOOLEAN] → STRING || (NIL STRING)
836
+(defun p2p-stream-close (&key (identifier nil) (all ""))
837
+  "Close an active p2p stream.
838
+  /ipns/docs.ipfs.io/reference/api/http/#api-v0-p2p-stream-close"
839
+  (bind-api-result
840
+    (ipfs-call "p2p/stream/close" `(,(when identifier `("arg" ,identifier))
841
+				     ,(when (not (empty-string-p all))
842
+					`("all" ,all))))
843
+    result))
844
+
845
+;; NIL → ALIST || (NIL STRING)
846
+(defun p2p-stream-ls ()
847
+  "List active p2p streams.
848
+  /ipns/docs.ipfs.io/reference/api/http/#api-v0-p2p-stream-ls"
849
+  (bind-api-alist (ipfs-call "p2p/stream/ls" '())))
850
+
851
+
852
+
853
+
783 854
 ;; —————————————————————————————————————
784 855
 ;; PUBSUB CALLS
785 856
 
... ...
@@ -112,6 +112,13 @@
112 112
     :object-stat
113 113
     ;; absentees— :object-put, :object-set-data, :object-patch-append-data
114 114
 
115
+    ;; p2p calls
116
+    :p2p-close
117
+    :p2p-listen
118
+    :p2p-ls
119
+    :p2p-stream-close
120
+    :p2p-stream-ls
121
+
115 122
     ;; pubsub calls
116 123
     :pubsub-sub
117 124
     :pubsub-sub-process