builtin/network, interface/packet_stream: Catch unknown packet exceptions and log them as warnings
This commit is contained in:
parent
44596b6d13
commit
990569c02a
@ -213,12 +213,16 @@ struct Module: public interface::Module, public network::Interface
|
|||||||
log_i(MODULE, "Received %zu bytes", r);
|
log_i(MODULE, "Received %zu bytes", r);
|
||||||
peer.socket_buffer.insert(peer.socket_buffer.end(), buf, buf + r);
|
peer.socket_buffer.insert(peer.socket_buffer.end(), buf, buf + r);
|
||||||
|
|
||||||
peer.packet_stream.input(peer.socket_buffer,
|
try {
|
||||||
[&](const ss_ & name, const ss_ & data){
|
peer.packet_stream.input(peer.socket_buffer,
|
||||||
// Emit event
|
[&](const ss_ & name, const ss_ & data){
|
||||||
m_server->emit_event(ss_()+"network:packet_received/"+name,
|
// Emit event
|
||||||
new Packet(peer.id, name, data));
|
m_server->emit_event(ss_()+"network:packet_received/"+name,
|
||||||
});
|
new Packet(peer.id, name, data));
|
||||||
|
});
|
||||||
|
} catch(interface::UnknownPacketReceived &e){
|
||||||
|
log_w(MODULE, "%s", e.what());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void send_u(Peer &peer, const ss_ &name, const ss_ &data)
|
void send_u(Peer &peer, const ss_ &name, const ss_ &data)
|
||||||
|
@ -9,6 +9,11 @@ namespace interface
|
|||||||
{
|
{
|
||||||
typedef size_t PacketType;
|
typedef size_t PacketType;
|
||||||
|
|
||||||
|
struct UnknownPacketReceived: public Exception {
|
||||||
|
ss_ msg;
|
||||||
|
UnknownPacketReceived(const ss_ &msg): Exception(msg){}
|
||||||
|
};
|
||||||
|
|
||||||
struct OutgoingPacketTypeRegistry
|
struct OutgoingPacketTypeRegistry
|
||||||
{
|
{
|
||||||
sm_<ss_, PacketType> m_types;
|
sm_<ss_, PacketType> m_types;
|
||||||
@ -32,7 +37,7 @@ namespace interface
|
|||||||
auto it = m_names.find(type);
|
auto it = m_names.find(type);
|
||||||
if(it != m_names.end())
|
if(it != m_names.end())
|
||||||
return it->second;
|
return it->second;
|
||||||
throw Exception(ss_()+"Packet type not known: "+itos(type));
|
throw UnknownPacketReceived(ss_()+"Packet type not known: "+itos(type));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -49,13 +54,13 @@ namespace interface
|
|||||||
auto it = m_types.find(name);
|
auto it = m_types.find(name);
|
||||||
if(it != m_types.end())
|
if(it != m_types.end())
|
||||||
return it->second;
|
return it->second;
|
||||||
throw Exception(ss_()+"Packet not known: "+name);
|
throw UnknownPacketReceived(ss_()+"Packet not known: "+name);
|
||||||
}
|
}
|
||||||
ss_ get_name(PacketType type){
|
ss_ get_name(PacketType type){
|
||||||
auto it = m_names.find(type);
|
auto it = m_names.find(type);
|
||||||
if(it != m_names.end())
|
if(it != m_names.end())
|
||||||
return it->second;
|
return it->second;
|
||||||
throw Exception(ss_()+"Packet not known: "+itos(type));
|
throw UnknownPacketReceived(ss_()+"Packet not known: "+itos(type));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user