Skip to content

Commit

Permalink
Fix gateway field setup for uplink
Browse files Browse the repository at this point in the history
  • Loading branch information
madninja committed Aug 8, 2023
1 parent feced04 commit 120dc1a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
9 changes: 6 additions & 3 deletions src/gateway.rs
@@ -1,6 +1,6 @@
use crate::{
beaconer, packet, packet_router, region_watcher, sync, PacketDown, PacketUp, RegionParams,
Result, Settings,
beaconer, packet, packet_router, region_watcher, sync, PacketDown, PacketUp, PublicKey,
RegionParams, Result, Settings,
};
use beacon::Beacon;
use lorawan::PHYPayload;
Expand Down Expand Up @@ -60,6 +60,7 @@ impl MessageSender {
}

pub struct Gateway {
public_key: PublicKey,
messages: MessageReceiver,
uplinks: packet_router::MessageSender,
beacons: beaconer::MessageSender,
Expand All @@ -79,7 +80,9 @@ impl Gateway {
beacons: beaconer::MessageSender,
) -> Result<Self> {
let region_params = region_watcher::current_value(&region_watch);
let public_key = settings.keypair.public_key().clone();
let gateway = Gateway {
public_key,
messages,
uplinks,
beacons,
Expand Down Expand Up @@ -136,7 +139,7 @@ impl Gateway {
info!(%mac, %addr, "disconnected packet forwarder")
}
Event::PacketReceived(rxpk, _gateway_mac) => {
match PacketUp::from_rxpk(rxpk, self.region_params.region) {
match PacketUp::from_rxpk(rxpk, &self.public_key, self.region_params.region) {
Ok(packet) if packet.is_potential_beacon() => {
self.handle_potential_beacon(packet).await;
}
Expand Down
6 changes: 3 additions & 3 deletions src/packet.rs
@@ -1,4 +1,4 @@
use crate::{error::DecodeError, Error, Region, Result};
use crate::{error::DecodeError, Error, PublicKey, Region, Result};
use helium_proto::services::{
poc_lora,
router::{PacketRouterPacketDownV1, PacketRouterPacketUpV1},
Expand Down Expand Up @@ -88,7 +88,7 @@ impl TryFrom<PacketUp> for poc_lora::LoraWitnessReportReqV1 {
}

impl PacketUp {
pub fn from_rxpk(rxpk: push_data::RxPk, region: Region) -> Result<Self> {
pub fn from_rxpk(rxpk: push_data::RxPk, gateway: &PublicKey, region: Region) -> Result<Self> {
if rxpk.get_crc_status() != &CRC::OK {
return Err(DecodeError::invalid_crc());
}
Expand All @@ -105,7 +105,7 @@ impl PacketUp {
snr: rxpk.get_snr(),
region: region.into(),
hold_time: 0,
gateway: vec![],
gateway: gateway.into(),
signature: vec![],
};
Ok(Self(packet))
Expand Down
1 change: 0 additions & 1 deletion src/packet_router/mod.rs
Expand Up @@ -258,7 +258,6 @@ pub async fn mk_uplink(
use std::ops::Deref;
let mut uplink: PacketRouterPacketUpV1 = packet.deref().into();
uplink.hold_time = packet.hold_time().as_millis() as u64;
uplink.gateway = keypair.public_key().into();
uplink.signature = sign(keypair, uplink.encode_to_vec()).await?;
let envelope = envelope_up_v1::Data::Packet(uplink);
Ok(envelope)
Expand Down

0 comments on commit 120dc1a

Please sign in to comment.