add rpc protocol utilities
This commit is contained in:
parent
c5c7f26fe9
commit
45271e2bac
|
@ -49,11 +49,11 @@ takes the difficulty out of creating custom brute force jobs
|
||||||
- low priority: randomized input space distribution
|
- low priority: randomized input space distribution
|
||||||
- ability to compile input generator with different parameters and distribute to agents
|
- ability to compile input generator with different parameters and distribute to agents
|
||||||
- low priority: support for multiple architectures
|
- low priority: support for multiple architectures
|
||||||
- agent authentication
|
- ✅ agent authentication
|
||||||
- client authentication
|
- ✅ client authentication
|
||||||
|
|
||||||
# agent: accept and run jobs
|
# agent: accept and run jobs
|
||||||
- securely connect to server
|
- ✅ securely connect to server
|
||||||
- retrieve assigned tasks
|
- retrieve assigned tasks
|
||||||
- report number of cores available (configurable limit)
|
- report number of cores available (configurable limit)
|
||||||
- report work rate
|
- report work rate
|
||||||
|
@ -61,8 +61,8 @@ takes the difficulty out of creating custom brute force jobs
|
||||||
- low priority: defer to external brute force program (eg, hashcat on GPU)
|
- low priority: defer to external brute force program (eg, hashcat on GPU)
|
||||||
|
|
||||||
# client: submit jobs and view progress
|
# client: submit jobs and view progress
|
||||||
|
- ✅securely connect to server
|
||||||
- command line interface
|
- command line interface
|
||||||
- securely connect to server
|
|
||||||
- `crossfire new`: create new crossfire project
|
- `crossfire new`: create new crossfire project
|
||||||
- `crossfire test`: test project locally, replicates configuration of server with single local
|
- `crossfire test`: test project locally, replicates configuration of server with single local
|
||||||
agent to debug issues
|
agent to debug issues
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
;; node info (not all fields will always be present)
|
;; node info (not all fields will always be present)
|
||||||
;; type: 'server 'agent 'client
|
;; type: 'server 'agent 'client
|
||||||
(struct node [id name type pubkey seckey host port] #:transparent)
|
(struct node [id name type pubkey seckey host port] #:transparent)
|
||||||
|
(provide (struct-out node))
|
||||||
|
|
||||||
;; creates an exn:fail to be passed by thread mailbox
|
;; creates an exn:fail to be passed by thread mailbox
|
||||||
(define (make-error str)
|
(define (make-error str)
|
||||||
|
@ -341,6 +342,9 @@
|
||||||
(comms-connect comms to-id))
|
(comms-connect comms to-id))
|
||||||
(comms-dispatch-msg comms to-id msg)))
|
(comms-dispatch-msg comms to-id msg)))
|
||||||
|
|
||||||
|
(provide make-comms comms-listen comms-connect comms-get-node-info comms-set-node-info)
|
||||||
|
|
||||||
|
;; transactional messages support
|
||||||
|
|
||||||
(define (transaction-manager my-node comms startup-thd)
|
(define (transaction-manager my-node comms startup-thd)
|
||||||
(define run-tm #t)
|
(define run-tm #t)
|
||||||
|
@ -484,42 +488,43 @@
|
||||||
(define (tm-shutdown tm)
|
(define (tm-shutdown tm)
|
||||||
(thread-sendrecv tm 'shutdown (void)))
|
(thread-sendrecv tm 'shutdown (void)))
|
||||||
|
|
||||||
|
(provide make-transaction-manager tm-register-rpc tm-deregister-rpc tm-transact tm-shutdown)
|
||||||
|
|
||||||
;; demo code
|
; ;; demo code
|
||||||
(define server-sk #"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
|
; (define server-sk #"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
|
||||||
(define server-pk (crypto-sign-public-key server-sk))
|
; (define server-pk (crypto-sign-public-key server-sk))
|
||||||
(define client-sk #"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")
|
; (define client-sk #"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")
|
||||||
(define client-pk (crypto-sign-public-key client-sk))
|
; (define client-pk (crypto-sign-public-key client-sk))
|
||||||
|
;
|
||||||
(define server-node (node 0 "server" 'server server-pk server-sk "localhost" 1337))
|
; (define server-node (node 0 "server" 'server server-pk server-sk "localhost" 1337))
|
||||||
(define client-node (node 1 "client" 'client client-pk client-sk #f #f))
|
; (define client-node (node 1 "client" 'client client-pk client-sk #f #f))
|
||||||
|
;
|
||||||
(require racket/cmdline)
|
; (require racket/cmdline)
|
||||||
|
;
|
||||||
(define mode
|
; (define mode
|
||||||
(command-line #:args (mode) mode))
|
; (command-line #:args (mode) mode))
|
||||||
(match mode
|
; (match mode
|
||||||
["server"
|
; ["server"
|
||||||
(define comms (make-comms server-node))
|
; (define comms (make-comms server-node))
|
||||||
(comms-set-node-info comms client-node)
|
; (comms-set-node-info comms client-node)
|
||||||
(define tm (make-transaction-manager server-node comms))
|
; (define tm (make-transaction-manager server-node comms))
|
||||||
(tm-register-rpc tm 'add1 add1)
|
; (tm-register-rpc tm 'add1 add1)
|
||||||
|
;
|
||||||
(comms-listen comms 1337)
|
; (comms-listen comms 1337)
|
||||||
|
;
|
||||||
(displayln "listening")
|
; (displayln "listening")
|
||||||
(sleep 9999)
|
; (sleep 9999)
|
||||||
|
;
|
||||||
(tm-shutdown tm)
|
; (tm-shutdown tm)
|
||||||
(comms-shutdown comms)]
|
; (comms-shutdown comms)]
|
||||||
["client"
|
; ["client"
|
||||||
(define comms (make-comms client-node))
|
; (define comms (make-comms client-node))
|
||||||
(comms-set-node-info comms server-node)
|
; (comms-set-node-info comms server-node)
|
||||||
(define tm (make-transaction-manager client-node comms))
|
; (define tm (make-transaction-manager client-node comms))
|
||||||
|
;
|
||||||
(displayln "transacting...")
|
; (displayln "transacting...")
|
||||||
(displayln (tm-transact tm 0 'add1 (list 1)))
|
; (displayln (tm-transact tm 0 'add1 (list 1)))
|
||||||
(displayln "done")
|
; (displayln "done")
|
||||||
|
;
|
||||||
(tm-shutdown tm)
|
; (tm-shutdown tm)
|
||||||
(comms-shutdown comms)])
|
; (comms-shutdown comms)])
|
||||||
|
|
|
@ -0,0 +1,72 @@
|
||||||
|
#lang racket/base
|
||||||
|
;; crossfire: distributed brute force infrastructure
|
||||||
|
;;
|
||||||
|
;; Copyright (C) 2020 haskal
|
||||||
|
;;
|
||||||
|
;; This program is free software: you can redistribute it and/or modify
|
||||||
|
;; it under the terms of the GNU Affero General Public License as published by
|
||||||
|
;; the Free Software Foundation, either version 3 of the License, or
|
||||||
|
;; (at your option) any later version.
|
||||||
|
;;
|
||||||
|
;; This program is distributed in the hope that it will be useful,
|
||||||
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
;; GNU Affero General Public License for more details.
|
||||||
|
;;
|
||||||
|
;; You should have received a copy of the GNU Affero General Public License
|
||||||
|
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
(require "comms.rkt" "not-crypto.rkt"
|
||||||
|
syntax/parse/define
|
||||||
|
(for-syntax racket/base racket/syntax))
|
||||||
|
|
||||||
|
;; utility functions and macros for defining rpcs
|
||||||
|
|
||||||
|
;; id generation helpers
|
||||||
|
(define-for-syntax (rpc-type-id what)
|
||||||
|
(format-id what "rpc-type-~a" (syntax-e what)))
|
||||||
|
(define-for-syntax (rpc-impl-id what)
|
||||||
|
(format-id what "rpc-impl-~a" (syntax-e what)))
|
||||||
|
|
||||||
|
;; parameters for comms, tm, and targeted node
|
||||||
|
(define current-comms (make-parameter #f))
|
||||||
|
(define current-tm (make-parameter #f))
|
||||||
|
(define current-to-node (make-parameter #f))
|
||||||
|
|
||||||
|
;; defines a class of rpcs
|
||||||
|
(define-simple-macro (define-rpc-type type:id)
|
||||||
|
#:with def-id (rpc-type-id #'type)
|
||||||
|
(define def-id (make-hash)))
|
||||||
|
|
||||||
|
;; defines an rpc implementation, registers it with a given class of rpcs and makes a wrapper to
|
||||||
|
;; call it
|
||||||
|
(define-simple-macro (define-rpc type:id (name:id args:id ...) body:expr ...)
|
||||||
|
#:with def-id (rpc-type-id #'type)
|
||||||
|
#:with impl-id (rpc-impl-id #'name)
|
||||||
|
(begin
|
||||||
|
(define (impl-id args ...) body ...)
|
||||||
|
(define (name args ...)
|
||||||
|
(tm-transact (current-tm) (current-to-node) (quote name) (list args ...)))
|
||||||
|
(hash-set! def-id (quote name) impl-id)))
|
||||||
|
|
||||||
|
;; installs all rpcs of a given rpc class into the transaction manager
|
||||||
|
(define-simple-macro (install-rpc-type type:id)
|
||||||
|
#:with def-id (rpc-type-id #'type)
|
||||||
|
(for ([(k v) (in-hash def-id)])
|
||||||
|
(tm-register-rpc (current-tm) k v)))
|
||||||
|
|
||||||
|
|
||||||
|
;; ok now we get to the real stuff
|
||||||
|
;; server rpc functions
|
||||||
|
|
||||||
|
(define-rpc-type server)
|
||||||
|
|
||||||
|
(define-rpc server (test-rpc a b)
|
||||||
|
(displayln "test rpc")
|
||||||
|
(displayln b)
|
||||||
|
(add1 a))
|
||||||
|
|
||||||
|
|
||||||
|
;; agent rpc functions
|
||||||
|
|
||||||
|
;; TODO ...
|
Loading…
Reference in New Issue