1
1
use crate :: {
2
2
errors:: NodeResult , node:: DriaComputeNode , p2p:: P2PMessage , utils:: get_current_time_nanos,
3
3
} ;
4
+ use async_trait:: async_trait;
4
5
use libp2p:: gossipsub:: MessageAcceptance ;
5
6
use ollama_workflows:: { Model , ModelProvider } ;
6
7
use serde:: { Deserialize , Serialize } ;
7
8
9
+ use super :: ComputeHandler ;
10
+
11
+ pub struct PingpongHandler ;
12
+
8
13
#[ derive( Serialize , Deserialize , Debug , Clone ) ]
9
14
struct PingpongPayload {
10
15
uuid : String ,
@@ -18,19 +23,10 @@ struct PingpongResponse {
18
23
pub ( crate ) timestamp : u128 ,
19
24
}
20
25
21
- /// A ping-pong is a message sent by a node to indicate that it is alive.
22
- /// Compute nodes listen to `pong` topic, and respond to `ping` topic.
23
- pub trait HandlesPingpong {
24
- fn handle_heartbeat (
25
- & mut self ,
26
- message : P2PMessage ,
27
- result_topic : & str ,
28
- ) -> NodeResult < MessageAcceptance > ;
29
- }
30
-
31
- impl HandlesPingpong for DriaComputeNode {
32
- fn handle_heartbeat (
33
- & mut self ,
26
+ #[ async_trait]
27
+ impl ComputeHandler for PingpongHandler {
28
+ async fn handle_compute (
29
+ node : & mut DriaComputeNode ,
34
30
message : P2PMessage ,
35
31
result_topic : & str ,
36
32
) -> NodeResult < MessageAcceptance > {
@@ -53,15 +49,15 @@ impl HandlesPingpong for DriaComputeNode {
53
49
// respond
54
50
let response_body = PingpongResponse {
55
51
uuid : pingpong. uuid . clone ( ) ,
56
- models : self . config . model_config . models . clone ( ) ,
52
+ models : node . config . model_config . models . clone ( ) ,
57
53
timestamp : get_current_time_nanos ( ) ,
58
54
} ;
59
55
let response = P2PMessage :: new_signed (
60
56
serde_json:: json!( response_body) . to_string ( ) ,
61
57
result_topic,
62
- & self . config . secret_key ,
58
+ & node . config . secret_key ,
63
59
) ;
64
- self . publish ( response) ?;
60
+ node . publish ( response) ?;
65
61
66
62
// accept message, someone else may be included in the filter
67
63
Ok ( MessageAcceptance :: Accept )
0 commit comments