update bytes(protobuf types) mapping, from Vec<u8> to bytes:Byte

issues:958
This commit is contained in:
tom 2022-07-16 00:45:23 +08:00
parent c6c5d2cb98
commit efa6b5972d
13 changed files with 34 additions and 25 deletions

View File

@ -55,6 +55,7 @@ rpassword = "6.0"
base64 = "0.13" base64 = "0.13"
sysinfo = "0.23" sysinfo = "0.23"
num_cpus = "1.13" num_cpus = "1.13"
bytes = "1.1"
[target.'cfg(not(target_os = "linux"))'.dependencies] [target.'cfg(not(target_os = "linux"))'.dependencies]
reqwest = { version = "0.11", features = ["json", "rustls-tls"], default-features=false } reqwest = { version = "0.11", features = ["json", "rustls-tls"], default-features=false }

View File

@ -5,6 +5,11 @@ fn main() {
.out_dir("src/protos") .out_dir("src/protos")
.inputs(&["protos/rendezvous.proto", "protos/message.proto"]) .inputs(&["protos/rendezvous.proto", "protos/message.proto"])
.include("protos") .include("protos")
.customize(
protobuf_codegen::Customize::default()
.tokio_bytes(true)
// .tokio_bytes_for_string(true)
)
.run() .run()
.expect("Codegen failed."); .expect("Codegen failed.");
} }

View File

@ -12,6 +12,7 @@ use crate::STRIDE_ALIGN;
use super::vpx::{vp8e_enc_control_id::*, vpx_codec_err_t::*, *}; use super::vpx::{vp8e_enc_control_id::*, vpx_codec_err_t::*, *};
use std::os::raw::{c_int, c_uint}; use std::os::raw::{c_int, c_uint};
use std::{ptr, slice}; use std::{ptr, slice};
use hbb_common::bytes::Bytes;
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum VpxVideoCodecId { pub enum VpxVideoCodecId {
@ -291,7 +292,7 @@ impl VpxEncoder {
#[inline] #[inline]
fn create_frame(frame: &EncodeFrame) -> EncodedVideoFrame { fn create_frame(frame: &EncodeFrame) -> EncodedVideoFrame {
EncodedVideoFrame { EncodedVideoFrame {
data: frame.data.to_vec(), data: Bytes::from(frame.data.to_vec()),
key: frame.key, key: frame.key,
pts: frame.pts, pts: frame.pts,
..Default::default() ..Default::default()

View File

@ -201,7 +201,7 @@ impl Client {
} else { } else {
peer_nat_type = ph.nat_type(); peer_nat_type = ph.nat_type();
is_local = ph.is_local(); is_local = ph.is_local();
signed_id_pk = ph.pk; signed_id_pk = ph.pk.as_ref().to_vec();
relay_server = ph.relay_server; relay_server = ph.relay_server;
peer_addr = AddrMangle::decode(&ph.socket_addr); peer_addr = AddrMangle::decode(&ph.socket_addr);
log::info!("Hole Punched {} = {}", peer, peer_addr); log::info!("Hole Punched {} = {}", peer, peer_addr);
@ -393,8 +393,8 @@ impl Client {
let sealed_key = box_::seal(&key.0, &nonce, &their_pk_b, &out_sk_b); let sealed_key = box_::seal(&key.0, &nonce, &their_pk_b, &out_sk_b);
let mut msg_out = Message::new(); let mut msg_out = Message::new();
msg_out.set_public_key(PublicKey { msg_out.set_public_key(PublicKey {
asymmetric_value: our_pk_b.0.into(), asymmetric_value: Vec::from(our_pk_b.0).into(),
symmetric_value: sealed_key, symmetric_value: sealed_key.into(),
..Default::default() ..Default::default()
}); });
timeout(CONNECT_TIMEOUT, conn.send(&msg_out)).await??; timeout(CONNECT_TIMEOUT, conn.send(&msg_out)).await??;
@ -1122,7 +1122,7 @@ impl LoginConfigHandler {
let my_id = Config::get_id(); let my_id = Config::get_id();
let mut lr = LoginRequest { let mut lr = LoginRequest {
username: self.id.clone(), username: self.id.clone(),
password, password:password.into(),
my_id, my_id,
my_name: crate::username(), my_name: crate::username(),
option: self.get_option_message(true).into(), option: self.get_option_message(true).into(),

View File

@ -67,7 +67,7 @@ pub fn clip_2_msg(clip: ClipbaordFile) -> Message {
CliprdrServerFormatDataResponse { CliprdrServerFormatDataResponse {
conn_id, conn_id,
msg_flags, msg_flags,
format_data, format_data: format_data.into(),
..Default::default() ..Default::default()
}, },
)), )),
@ -117,7 +117,7 @@ pub fn clip_2_msg(clip: ClipbaordFile) -> Message {
conn_id, conn_id,
msg_flags, msg_flags,
stream_id, stream_id,
requested_data, requested_data: requested_data.into(),
..Default::default() ..Default::default()
}, },
)), )),
@ -156,7 +156,7 @@ pub fn msg_2_clip(msg: Cliprdr) -> Option<ClipbaordFile> {
Some(ClipbaordFile::ServerFormatDataResponse { Some(ClipbaordFile::ServerFormatDataResponse {
conn_id: data.conn_id, conn_id: data.conn_id,
msg_flags: data.msg_flags, msg_flags: data.msg_flags,
format_data: data.format_data, format_data: data.format_data.as_ref().to_vec(),
}) })
} }
Some(cliprdr::Union::FileContentsRequest(data)) => { Some(cliprdr::Union::FileContentsRequest(data)) => {
@ -177,7 +177,7 @@ pub fn msg_2_clip(msg: Cliprdr) -> Option<ClipbaordFile> {
conn_id: data.conn_id, conn_id: data.conn_id,
msg_flags: data.msg_flags, msg_flags: data.msg_flags,
stream_id: data.stream_id, stream_id: data.stream_id,
requested_data: data.requested_data, requested_data: data.requested_data.as_ref().to_vec(),
}) })
} }
_ => None, _ => None,

View File

@ -49,7 +49,7 @@ pub fn create_clipboard_msg(content: String) -> Message {
let mut msg = Message::new(); let mut msg = Message::new();
msg.set_clipboard(Clipboard { msg.set_clipboard(Clipboard {
compress, compress,
content, content:content.into(),
..Default::default() ..Default::default()
}); });
msg msg
@ -80,7 +80,7 @@ pub fn update_clipboard(clipboard: Clipboard, old: Option<&Arc<Mutex<String>>>)
let content = if clipboard.compress { let content = if clipboard.compress {
decompress(&clipboard.content) decompress(&clipboard.content)
} else { } else {
clipboard.content clipboard.content.as_ref().to_vec()
}; };
if let Ok(content) = String::from_utf8(content) { if let Ok(content) = String::from_utf8(content) {
if content.is_empty() { if content.is_empty() {

View File

@ -164,7 +164,7 @@ pub fn get_cursor_data(hcursor: u64) -> ResultType<CursorData> {
Ok(CursorData { Ok(CursorData {
id: hcursor, id: hcursor,
colors: cbits, colors: cbits.into(),
hotx: ii.0.xHotspot as _, hotx: ii.0.xHotspot as _,
hoty: ii.0.yHotspot as _, hoty: ii.0.yHotspot as _,
width: width as _, width: width as _,

View File

@ -263,7 +263,7 @@ impl RendezvousMediator {
async fn handle_request_relay(&self, rr: RequestRelay, server: ServerPtr) -> ResultType<()> { async fn handle_request_relay(&self, rr: RequestRelay, server: ServerPtr) -> ResultType<()> {
self.create_relay( self.create_relay(
rr.socket_addr, rr.socket_addr.as_ref().to_vec(),
rr.relay_server, rr.relay_server,
rr.uuid, rr.uuid,
server, server,
@ -300,7 +300,7 @@ impl RendezvousMediator {
let mut msg_out = Message::new(); let mut msg_out = Message::new();
let mut rr = RelayResponse { let mut rr = RelayResponse {
socket_addr, socket_addr: socket_addr.into(),
version: crate::VERSION.to_owned(), version: crate::VERSION.to_owned(),
..Default::default() ..Default::default()
}; };
@ -331,8 +331,8 @@ impl RendezvousMediator {
let relay_server = self.get_relay_server(fla.relay_server); let relay_server = self.get_relay_server(fla.relay_server);
msg_out.set_local_addr(LocalAddr { msg_out.set_local_addr(LocalAddr {
id: Config::get_id(), id: Config::get_id(),
socket_addr: AddrMangle::encode(peer_addr), socket_addr: AddrMangle::encode(peer_addr).into(),
local_addr: AddrMangle::encode(local_addr), local_addr: AddrMangle::encode(local_addr).into(),
relay_server, relay_server,
version: crate::VERSION.to_owned(), version: crate::VERSION.to_owned(),
..Default::default() ..Default::default()
@ -350,7 +350,7 @@ impl RendezvousMediator {
{ {
let uuid = Uuid::new_v4().to_string(); let uuid = Uuid::new_v4().to_string();
return self return self
.create_relay(ph.socket_addr, relay_server, uuid, server, true, true) .create_relay(ph.socket_addr.as_ref().to_vec(), relay_server, uuid, server, true, true)
.await; .await;
} }
let peer_addr = AddrMangle::decode(&ph.socket_addr); let peer_addr = AddrMangle::decode(&ph.socket_addr);
@ -391,8 +391,8 @@ impl RendezvousMediator {
self.last_id_pk_registry = id.clone(); self.last_id_pk_registry = id.clone();
msg_out.set_register_pk(RegisterPk { msg_out.set_register_pk(RegisterPk {
id, id,
uuid, uuid: uuid.into(),
pk, pk: pk.into(),
..Default::default() ..Default::default()
}); });
socket.send(&msg_out, self.addr.to_owned()).await?; socket.send(&msg_out, self.addr.to_owned()).await?;

View File

@ -20,6 +20,8 @@ use std::{
sync::{Arc, Mutex, RwLock, Weak}, sync::{Arc, Mutex, RwLock, Weak},
time::Duration, time::Duration,
}; };
use bytes::Bytes;
pub mod audio_service; pub mod audio_service;
cfg_if::cfg_if! { cfg_if::cfg_if! {
if #[cfg(not(any(target_os = "android", target_os = "ios")))] { if #[cfg(not(any(target_os = "android", target_os = "ios")))] {
@ -126,13 +128,13 @@ pub async fn create_tcp_connection(
id: sign::sign( id: sign::sign(
&IdPk { &IdPk {
id: Config::get_id(), id: Config::get_id(),
pk: our_pk_b.0.to_vec(), pk: Bytes::from(our_pk_b.0.to_vec()),
..Default::default() ..Default::default()
} }
.write_to_bytes() .write_to_bytes()
.unwrap_or_default(), .unwrap_or_default(),
&sk, &sk,
), ).into(),
..Default::default() ..Default::default()
}); });
timeout(CONNECT_TIMEOUT, stream.send(&msg_out)).await??; timeout(CONNECT_TIMEOUT, stream.send(&msg_out)).await??;

View File

@ -367,7 +367,7 @@ fn send_f32(data: &[f32], encoder: &mut Encoder, sp: &GenericService) {
Ok(data) => { Ok(data) => {
let mut msg_out = Message::new(); let mut msg_out = Message::new();
msg_out.set_audio_frame(AudioFrame { msg_out.set_audio_frame(AudioFrame {
data, data: data.into(),
timestamp: crate::common::get_time(), timestamp: crate::common::get_time(),
..Default::default() ..Default::default()
}); });

View File

@ -1063,7 +1063,7 @@ impl Connection {
self.send_fs(ipc::FS::WriteBlock { self.send_fs(ipc::FS::WriteBlock {
id: block.id, id: block.id,
file_num: block.file_num, file_num: block.file_num,
data: block.data, data: block.data.as_ref().to_vec(),
compressed: block.compressed, compressed: block.compressed,
}); });
} }

View File

@ -145,7 +145,7 @@ fn run_cursor(sp: MouseCursorService, state: &mut StateCursor) -> ResultType<()>
msg = cached.clone(); msg = cached.clone();
} else { } else {
let mut data = crate::get_cursor_data(hcursor)?; let mut data = crate::get_cursor_data(hcursor)?;
data.colors = hbb_common::compress::compress(&data.colors[..], COMPRESS_LEVEL); data.colors = hbb_common::compress::compress(&data.colors[..], COMPRESS_LEVEL).into();
let mut tmp = Message::new(); let mut tmp = Message::new();
tmp.set_cursor_data(data); tmp.set_cursor_data(data);
msg = Arc::new(tmp); msg = Arc::new(tmp);

View File

@ -263,7 +263,7 @@ impl ConnectionManager {
FileTransferBlock { FileTransferBlock {
id, id,
file_num, file_num,
data, data: data.into(),
compressed, compressed,
..Default::default() ..Default::default()
}, },