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);
|
||||
peer.socket_buffer.insert(peer.socket_buffer.end(), buf, buf + r);
|
||||
|
||||
peer.packet_stream.input(peer.socket_buffer,
|
||||
[&](const ss_ & name, const ss_ & data){
|
||||
// Emit event
|
||||
m_server->emit_event(ss_()+"network:packet_received/"+name,
|
||||
new Packet(peer.id, name, data));
|
||||
});
|
||||
try {
|
||||
peer.packet_stream.input(peer.socket_buffer,
|
||||
[&](const ss_ & name, const ss_ & data){
|
||||
// Emit event
|
||||
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)
|
||||
|
@ -9,6 +9,11 @@ namespace interface
|
||||
{
|
||||
typedef size_t PacketType;
|
||||
|
||||
struct UnknownPacketReceived: public Exception {
|
||||
ss_ msg;
|
||||
UnknownPacketReceived(const ss_ &msg): Exception(msg){}
|
||||
};
|
||||
|
||||
struct OutgoingPacketTypeRegistry
|
||||
{
|
||||
sm_<ss_, PacketType> m_types;
|
||||
@ -32,7 +37,7 @@ namespace interface
|
||||
auto it = m_names.find(type);
|
||||
if(it != m_names.end())
|
||||
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);
|
||||
if(it != m_types.end())
|
||||
return it->second;
|
||||
throw Exception(ss_()+"Packet not known: "+name);
|
||||
throw UnknownPacketReceived(ss_()+"Packet not known: "+name);
|
||||
}
|
||||
ss_ get_name(PacketType type){
|
||||
auto it = m_names.find(type);
|
||||
if(it != m_names.end())
|
||||
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