Skip to content

Commit

Permalink
Fix entry peer config code
Browse files Browse the repository at this point in the history
  • Loading branch information
kl authored and Pururun committed Nov 15, 2024
1 parent b05f141 commit e7bffe7
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions talpid-wireguard/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,28 +239,28 @@ pub fn userspace_format(

wg_conf.add("replace_peers", "true");

let peers = exit_peer
.as_ref()
.into_iter()
.chain(std::iter::once(&entry_peer));

for peer in peers {
wg_conf
.add::<&[u8]>("public_key", peer.public_key.as_bytes().as_ref())
.add("endpoint", peer.endpoint.to_string().as_str())
.add("replace_allowed_ips", "true");
if let Some(ref psk) = peer.psk {
wg_conf.add::<&[u8]>("preshared_key", psk.as_bytes().as_ref());
}
for addr in &peer.allowed_ips {
wg_conf.add("allowed_ip", addr.to_string().as_str());
}
#[cfg(daita)]
if peer.constant_packet_size {
wg_conf.add("constant_packet_size", "true");
}
if let Some(exit) = exit_peer {
write_peer_to_config(&mut wg_conf, exit)
}
write_peer_to_config(&mut wg_conf, entry_peer);

let bytes = wg_conf.into_config();
CString::new(bytes).expect("null bytes inside config")
}

fn write_peer_to_config(wg_conf: &mut WgConfigBuffer, peer: &PeerConfig) {
wg_conf
.add::<&[u8]>("public_key", peer.public_key.as_bytes().as_ref())
.add("endpoint", peer.endpoint.to_string().as_str())
.add("replace_allowed_ips", "true");
if let Some(ref psk) = peer.psk {
wg_conf.add::<&[u8]>("preshared_key", psk.as_bytes().as_ref());
}
for addr in &peer.allowed_ips {
wg_conf.add("allowed_ip", addr.to_string().as_str());
}
#[cfg(daita)]
if peer.constant_packet_size {
wg_conf.add("constant_packet_size", "true");
}
}

0 comments on commit e7bffe7

Please sign in to comment.