mirror of
https://github.com/threefoldtech/mycelium.git
synced 2026-06-07 00:01:40 +00:00
fixed imports, changed router function according to new packet structure
This commit is contained in:
+1
-1
@@ -1,7 +1,7 @@
|
||||
use std::{io, net::{IpAddr, Ipv4Addr}};
|
||||
use bytes::{BufMut, BytesMut, Buf};
|
||||
use tokio_util::codec::{Encoder, Decoder};
|
||||
use crate::packet::{Packet, ControlPacket, DataPacket, PacketType, ControlPacketBody, ControlPacketType, BabelTLVType, BabelPacketBody, BabelTLV, BabelPacketHeader};
|
||||
use crate::packet::{Packet, ControlPacket, DataPacket, PacketType, BabelTLVType, BabelPacketBody, BabelTLV, BabelPacketHeader};
|
||||
|
||||
/* ********************************PAKCET*********************************** */
|
||||
pub struct PacketCodec {
|
||||
|
||||
+22
-11
@@ -1,7 +1,7 @@
|
||||
use std::{net::{IpAddr, Ipv4Addr}, sync::{Mutex, Arc}};
|
||||
use std::{net::{Ipv4Addr}, sync::{Mutex, Arc}};
|
||||
use tokio::sync::mpsc::{UnboundedSender, UnboundedReceiver, self};
|
||||
use tokio_tun::Tun;
|
||||
use crate::{peer::Peer, packet::{ControlPacket, ControlPacketType, DataPacket, ControlStruct}};
|
||||
use crate::{peer::Peer, packet::{ControlPacket, DataPacket, ControlStruct, BabelTLVType, BabelPacketHeader, BabelPacketBody, BabelTLV}};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Router {
|
||||
@@ -34,16 +34,17 @@ impl Router {
|
||||
}
|
||||
|
||||
async fn handle_incoming_control_packets(mut router_control_rx: UnboundedReceiver<ControlStruct>) {
|
||||
loop {
|
||||
while let Some(control_struct) = router_control_rx.recv().await {
|
||||
match control_struct.control_packet.message_type {
|
||||
ControlPacketType::Hello => {
|
||||
loop {
|
||||
while let Some(control_struct) = router_control_rx.recv().await {
|
||||
if let Some(body) = &control_struct.control_packet.body {
|
||||
match body.tlv_type {
|
||||
BabelTLVType::Hello => {
|
||||
let dest_ip = control_struct.src_overlay_ip;
|
||||
control_struct.reply(ControlPacket::new_ihu(10, 1000, dest_ip));
|
||||
println!("IHU {}", dest_ip);
|
||||
},
|
||||
ControlPacketType::IHU => {
|
||||
// Upon receiving an IHU, nothing parrticular needs to be done.
|
||||
BabelTLVType::IHU => {
|
||||
// Upon receiving an IHU, nothing particular needs to be done.
|
||||
},
|
||||
_ => {
|
||||
eprintln!("Unknown control packet type");
|
||||
@@ -51,6 +52,7 @@ impl Router {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn handle_incoming_data_packets(self, mut router_data_rx: UnboundedReceiver<DataPacket>) {
|
||||
@@ -84,11 +86,20 @@ impl Router {
|
||||
async fn start_hello_sender(self) {
|
||||
loop {
|
||||
tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;
|
||||
|
||||
let hello_message = ControlPacket {
|
||||
message_type: ControlPacketType::Hello,
|
||||
body_length: 0,
|
||||
body: Some(crate::packet::ControlPacketBody::Hello { flags: 100u16, seqno: 200u16, interval: 300u16 }),
|
||||
header: BabelPacketHeader::new(8),
|
||||
body: Some(BabelPacketBody {
|
||||
tlv_type: BabelTLVType::Hello,
|
||||
length: 8,
|
||||
body: BabelTLV::Hello {
|
||||
flags: 100u16,
|
||||
seqno: 200u16,
|
||||
interval: 300u16,
|
||||
},
|
||||
}),
|
||||
};
|
||||
|
||||
for peer in self.get_directly_connected_peers() {
|
||||
println!("Hello {}", peer.overlay_ip);
|
||||
if let Err(e) = peer.to_peer_control.send(hello_message.clone()) {
|
||||
|
||||
Reference in New Issue
Block a user