Messgaes sent from one local node to another don't need to be relayed by an external node. --- mesh/net.c | 51 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/mesh/net.c b/mesh/net.c index 2adae70c3..b173e1c09 100644 --- a/mesh/net.c +++ b/mesh/net.c @@ -254,10 +254,24 @@ struct net_decode { bool proxy; }; +struct net_queue_data { + struct mesh_io_recv_info *info; + struct mesh_net *net; + const uint8_t *data; + uint8_t *out; + size_t out_size; + enum _relay_advice relay_advice; + uint32_t key_id; + uint32_t iv_index; + uint16_t len; +}; + #define FAST_CACHE_SIZE 8 static struct l_queue *fast_cache; static struct l_queue *nets; +static void net_rx(void *net_ptr, void *user_data); + static inline struct mesh_subnet *get_primary_subnet(struct mesh_net *net) { return l_queue_peek_head(net->subnets); @@ -2267,16 +2281,27 @@ static void send_relay_pkt(struct mesh_net *net, uint8_t *data, uint8_t size) static void send_msg_pkt(struct mesh_net *net, uint8_t *packet, uint8_t size) { struct mesh_io *io = net->io; - struct mesh_io_send_info info = { - .type = MESH_IO_TIMING_TYPE_GENERAL, - .u.gen.interval = net->tx_interval, - .u.gen.cnt = net->tx_cnt, - .u.gen.min_delay = DEFAULT_MIN_DELAY, - /* No extra randomization when sending regular mesh messages */ - .u.gen.max_delay = DEFAULT_MIN_DELAY + struct mesh_io_send_info info; + struct net_queue_data net_data = { + .info = NULL, + .data = packet + 1, + .len = size - 1, + .relay_advice = RELAY_NONE, }; + /* Send to local nodes first */ + l_queue_foreach(nets, net_rx, &net_data); + + if (net_data.relay_advice == RELAY_DISALLOWED) + return; + packet[0] = MESH_AD_TYPE_NETWORK; + info.type = MESH_IO_TIMING_TYPE_GENERAL; + info.u.gen.interval = net->tx_interval; + info.u.gen.cnt = net->tx_cnt; + info.u.gen.min_delay = DEFAULT_MIN_DELAY; + /* No extra randomization when sending regular mesh messages */ + info.u.gen.max_delay = DEFAULT_MIN_DELAY; mesh_io_send(io, &info, packet, size); } @@ -2461,18 +2486,6 @@ static enum _relay_advice packet_received(void *user_data, return RELAY_NONE; } -struct net_queue_data { - struct mesh_io_recv_info *info; - struct mesh_net *net; - const uint8_t *data; - uint8_t *out; - size_t out_size; - enum _relay_advice relay_advice; - uint32_t key_id; - uint32_t iv_index; - uint16_t len; -}; - static void net_rx(void *net_ptr, void *user_data) { struct net_queue_data *data = user_data; -- 2.14.5