-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: channel pub-sub feature and tests. cluster integration test (#262)
* feat: channel pub-sub feature and tests. cluster integration test * chore: fix typos
- Loading branch information
Showing
7 changed files
with
539 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use std::hash::{DefaultHasher, Hash, Hasher}; | ||
|
||
use atm0s_sdn::features::dht_kv::{Key, Map}; | ||
use media_server_protocol::endpoint::{PeerId, TrackName}; | ||
|
||
use super::ClusterRoomHash; | ||
|
||
pub fn peer_map(room: ClusterRoomHash, peer: &PeerId) -> Map { | ||
let mut h = DefaultHasher::new(); | ||
room.as_ref().hash(&mut h); | ||
peer.as_ref().hash(&mut h); | ||
h.finish().into() | ||
} | ||
|
||
pub fn peers_map(room: ClusterRoomHash) -> Map { | ||
room.0.into() | ||
} | ||
|
||
pub fn peers_key(peer: &PeerId) -> Key { | ||
let mut h = DefaultHasher::new(); | ||
peer.as_ref().hash(&mut h); | ||
h.finish().into() | ||
} | ||
|
||
pub fn tracks_map(room: ClusterRoomHash) -> Map { | ||
(room.0 + 1).into() | ||
} | ||
|
||
pub fn tracks_key(peer: &PeerId, track: &TrackName) -> Key { | ||
let mut h = DefaultHasher::new(); | ||
peer.as_ref().hash(&mut h); | ||
track.as_ref().hash(&mut h); | ||
h.finish().into() | ||
} | ||
|
||
pub fn gen_channel_id<T: From<u64>>(room: ClusterRoomHash, peer: &PeerId, track: &TrackName) -> T { | ||
let mut h = std::hash::DefaultHasher::new(); | ||
room.as_ref().hash(&mut h); | ||
peer.as_ref().hash(&mut h); | ||
track.as_ref().hash(&mut h); | ||
h.finish().into() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.