Skip to content

Commit d6ff15d

Browse files
authored
feat: added openrouter support (#146)
* added openrouter * smol update * added blacklisting on wrong protocol
1 parent 89075e9 commit d6ff15d

File tree

10 files changed

+235
-64
lines changed

10 files changed

+235
-64
lines changed

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ OPENAI_API_KEY=
2828
## Gemini (if used, required) ##
2929
GEMINI_API_KEY=
3030

31+
## Open Router (if used, required) ##
32+
OPENROUTER_API_KEY=
33+
3134
## Ollama (if used, optional) ##
3235
# do not change this, it is used by Docker
3336
OLLAMA_HOST=http://host.docker.internal

Cargo.lock

Lines changed: 54 additions & 59 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ default-members = ["compute"]
77

88
[workspace.package]
99
edition = "2021"
10-
version = "0.2.21"
10+
version = "0.2.22"
1111
license = "Apache-2.0"
1212
readme = "README.md"
1313

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM --platform=$BUILDPLATFORM rust:1.75 as builder
1+
FROM --platform=$BUILDPLATFORM rust:1.75 AS builder
22

33
# https://docs.docker.com/engine/reference/builder/#automatic-platform-args-in-the-global-scope
44
#

compute/src/utils/message.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ pub struct DKNMessage {
2323
///
2424
/// NOTE: This can be obtained via Identify protocol version
2525
pub(crate) version: String,
26+
/// Identity protocol string of the Dria Compute Node
27+
#[serde(default)]
28+
pub(crate) identity: String,
2629
/// The timestamp of the message, in nanoseconds
2730
///
2831
/// NOTE: This can be obtained via DataTransform in GossipSub
@@ -46,6 +49,9 @@ impl DKNMessage {
4649
payload: BASE64_STANDARD.encode(data),
4750
topic: topic.to_string(),
4851
version: DRIA_COMPUTE_NODE_VERSION.to_string(),
52+
identity: dkn_p2p::P2P_IDENTITY_PREFIX
53+
.trim_end_matches('/')
54+
.to_string(),
4955
timestamp: get_current_time_nanos(),
5056
}
5157
}

p2p/src/client.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ impl DriaP2PClient {
254254
log::warn!("Local node is listening on {}", address);
255255
}
256256
SwarmEvent::ExternalAddrConfirmed { address } => {
257+
// this is usually the external address via relay
257258
log::info!("External address confirmed: {}", address);
258259
}
259260
event => log::trace!("Unhandled Swarm Event: {:?}", event),
@@ -275,6 +276,13 @@ impl DriaP2PClient {
275276
info.protocol_version,
276277
self.identity_protocol
277278
);
279+
280+
// blacklist peers with different protocol
281+
self.swarm
282+
.behaviour_mut()
283+
.gossipsub
284+
.blacklist_peer(&peer_id);
285+
278286
return;
279287
}
280288

p2p/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ mod client;
77
pub use client::DriaP2PClient;
88

99
/// Prefix for Kademlia protocol, must start with `/`!
10-
pub(crate) const P2P_KADEMLIA_PREFIX: &str = "/dria/kad/";
10+
pub const P2P_KADEMLIA_PREFIX: &str = "/dria/kad/";
1111

1212
/// Prefix for Identity protocol string.
13-
pub(crate) const P2P_IDENTITY_PREFIX: &str = "dria/";
13+
pub const P2P_IDENTITY_PREFIX: &str = "dria/";
1414

1515
// re-exports
1616
pub use libp2p;

0 commit comments

Comments
 (0)