bugfix/tratamento de excecao no receive() do udpSocket

This commit is contained in:
GustavoHMDS committed 2026-11-09 11:05:28 -03:00
1 parent acfee89563
commit fb2f4a7c18
2 files changed
+105 -67

No files matched your search

+45 -46
View File
@@ -4,8 +4,9 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="184f7582-9491-4541-9ea8-677e31b83cd6" name="Changes" comment=""> <list default="true" id="62118a1b-608f-4144-b29c-cf46419ca676" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/plugins.registry.json" beforeDir="false" afterPath="$PROJECT_DIR$/plugins.registry.json" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pitiupi/src/pitiupi/net/udp/SocketUDP.java" beforeDir="false" afterPath="$PROJECT_DIR$/pitiupi/src/pitiupi/net/udp/SocketUDP.java" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -16,80 +17,78 @@
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component> </component>
<component name="ProjectColorInfo">{ <component name="ProjectColorInfo">{
&quot;associatedIndex&quot;: 2, &quot;associatedIndex&quot;: 0
&quot;fromUser&quot;: false
}</component> }</component>
<component name="ProjectId" id="3GjM8jvhMxaHpSRoyB7jkVQR4Bc" /> <component name="ProjectId" id="3GbOdQKFlKqBjAjqjAv5TRPxr6Z" />
<component name="ProjectViewState"> <component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent">{ <component name="PropertiesComponent"><![CDATA[{
&quot;keyToString&quot;: { "keyToString": {
&quot;ModuleVcsDetector.initialDetectionPerformed&quot;: &quot;true&quot;, "Application.Main.executor": "Run",
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;, "ModuleVcsDetector.initialDetectionPerformed": "true",
&quot;RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager.252&quot;: &quot;true&quot;, "RunOnceActivity.ShowReadmeOnStart": "true",
&quot;RunOnceActivity.git.unshallow&quot;: &quot;true&quot;, "RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager.252": "true",
&quot;RunOnceActivity.typescript.service.memoryLimit.init&quot;: &quot;true&quot;, "RunOnceActivity.git.unshallow": "true",
&quot;codeWithMe.voiceChat.enabledByDefault&quot;: &quot;false&quot;, "git-widget-placeholder": "main",
&quot;git-widget-placeholder&quot;: &quot;main&quot;, "ignore.virus.scanning.warn.message": "true",
&quot;ignore.virus.scanning.warn.message&quot;: &quot;true&quot;, "kotlin-language-version-configured": "true",
&quot;kotlin-language-version-configured&quot;: &quot;true&quot;, "last_opened_file_path": "C:/Users/extre/OneDrive/Documentos/Faculdade/2026_02/Monitoria/Pitiupi",
&quot;last_opened_file_path&quot;: &quot;C:/Users/Gustavo/OneDrive/Documentos/Faculdade/2026_2/Monitoria/pitiupi&quot;, "project.structure.last.edited": "Modules",
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;, "project.structure.proportion": "0.0",
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;, "project.structure.side.proportion": "0.2",
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;, "settings.editor.selected.configurable": "preferences.keymap"
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
&quot;project.structure.last.edited&quot;: &quot;Project&quot;,
&quot;project.structure.proportion&quot;: &quot;0.0&quot;,
&quot;project.structure.side.proportion&quot;: &quot;0.0&quot;,
&quot;run.code.analysis.last.selected.profile&quot;: &quot;pProject Default&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;preferences.lookFeel&quot;
} }
}</component> }]]></component>
<component name="RecentsManager"> <component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS"> <key name="CopyFile.RECENT_KEYS">
<recent name="C:\Users\Gustavo\OneDrive\Documentos\Faculdade\2026_2\Monitoria\pitiupi\plugins\ping" /> <recent name="C:\Users\extre\OneDrive\Documentos\Faculdade\2026_02\Monitoria\Pitiupi\pitiupi\plugins" />
<recent name="C:\Users\Gustavo\OneDrive\Documentos\Faculdade\2026_2\Monitoria\pitiupi\pitiupi\plugins" /> <recent name="C:\Users\extre\OneDrive\Documentos\Faculdade\2026_02\Monitoria\Pitiupi\plugins\ping" />
</key> </key>
<key name="MoveFile.RECENT_KEYS"> <key name="MoveFile.RECENT_KEYS">
<recent name="C:\Users\Gustavo\OneDrive\Documentos\Faculdade\2026_2\Monitoria\pitiupi\plugins\ping" /> <recent name="C:\Users\extre\OneDrive\Documentos\Faculdade\2026_02\Monitoria\Pitiupi\plugins\ping" />
<recent name="C:\Users\Gustavo\OneDrive\Documentos\Faculdade\2026_2\Monitoria\pitiupi\pitiupi\plugins" /> <recent name="C:\Users\extre\OneDrive\Documentos\Faculdade\2026_02\Monitoria\Pitiupi\privateChat" />
<recent name="C:\Users\extre\OneDrive\Documentos\Faculdade\2026_02\Monitoria\Pitiupi\privateChat\src" />
<recent name="C:\Users\extre\OneDrive\Documentos\Faculdade\2026_02\Monitoria\Pitiupi\pitiupi\plugins" />
<recent name="C:\Users\extre\OneDrive\Documentos\Faculdade\2026_02\Monitoria\Pitiupi\pitiupi.mpChat\out\META-INF" />
</key> </key>
</component> </component>
<component name="RunManager"> <component name="RunManager">
<configuration default="true" type="JetRunConfigurationType"> <configuration name="Main" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="pitiupi.Main" />
<module name="pitiupi" /> <module name="pitiupi" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="pitiupi.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<method v="2"> <method v="2">
<option name="Make" enabled="true" /> <option name="Make" enabled="true" />
</method> </method>
</configuration> </configuration>
<configuration default="true" type="KotlinStandaloneScriptRunConfigurationType"> <recent_temporary>
<module name="pitiupi" /> <list>
<option name="filePath" /> <item itemvalue="Application.Main" />
<method v="2" /> </list>
</configuration> </recent_temporary>
</component> </component>
<component name="SharedIndexes"> <component name="SharedIndexes">
<attachedChunks> <attachedChunks>
<set> <set>
<option value="bundled-jdk-30f59d01ecdd-37e91769500f-intellij.indexing.shared.core-IU-261.26222.65" /> <option value="bundled-jdk-9823dce3aa75-bf35d07a577b-intellij.indexing.shared.core-IU-252.28539.149" />
<option value="bundled-js-predefined-d6986cc7102b-31caf2ab9e3c-JavaScript-IU-261.26222.65" />
</set> </set>
</attachedChunks> </attachedChunks>
</component> </component>
<component name="TaskManager"> <component name="TaskManager">
<task active="true" id="Default" summary="Default task"> <task active="true" id="Default" summary="Default task">
<changelist id="184f7582-9491-4541-9ea8-677e31b83cd6" name="Changes" comment="" /> <changelist id="62118a1b-608f-4144-b29c-cf46419ca676" name="Changes" comment="" />
<created>1784480367533</created> <created>1784236888334</created>
<option name="number" value="Default" /> <option name="number" value="Default" />
<option name="presentableId" value="Default" /> <option name="presentableId" value="Default" />
<updated>1784480367533</updated> <updated>1784236888334</updated>
</task> </task>
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
</project> </project>
+60 -21
View File
@@ -10,6 +10,7 @@ import java.io.IOException;
import java.io.ObjectInput; import java.io.ObjectInput;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.net.*; import java.net.*;
import java.util.Arrays;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@@ -163,37 +164,75 @@ public class SocketUDP extends Thread {
* @throws ClassNotFoundException caso ocorra um erro ao verificar uma * @throws ClassNotFoundException caso ocorra um erro ao verificar uma
* mensagem de heartbeat. * mensagem de heartbeat.
*/ */
public void receive() throws UnknownHostException, IOException, ClassNotFoundException { public void receive() throws IOException {
byte[] buf = new byte[256000]; byte[] buffer = new byte[256000];
while (running) { while (running) {
DatagramPacket msgPacket = new DatagramPacket(buf, buf.length); DatagramPacket packet = new DatagramPacket(
buffer,
buffer.length
);
try { try {
multicastSocket.receive(msgPacket); multicastSocket.receive(packet);
handlePacket(packet);
} catch (SocketException ex) {
if (!running) {
break;
}
Logger.getLogger(SocketUDP.class.getName())
.log(Level.SEVERE, "Erro no socket UDP", ex);
break;
} catch (IOException ex) { } catch (IOException ex) {
if (!running) { if (!running) {
break; break;
} }
throw ex;
}
Object coreMessage = tryParseCoreUdpMessage(msgPacket.getData()); Logger.getLogger(SocketUDP.class.getName())
if (coreMessage instanceof HeartbeatMessage heartbeat) { .log(Level.SEVERE, "Erro ao receber datagrama UDP", ex);
connectionManager.receiveHeartbeat(heartbeat, msgPacket.getAddress());
continue;
}
if (coreMessage instanceof GoodbyeMessage goodbye) {
connectionManager.receiveGoodbye(goodbye);
continue;
}
if (coreMessage instanceof SessionInviteMessage invite) {
connectionManager.receiveSessionInvite(invite);
continue;
}
pluginManager.handleMessage(msgPacket.getData()); break;
} catch (RuntimeException ex) {
Logger.getLogger(SocketUDP.class.getName())
.log(Level.WARNING, "Falha ao processar datagrama UDP", ex);
}
} }
} }
private void handlePacket(DatagramPacket packet) {
byte[] data = Arrays.copyOf(
packet.getData(),
packet.getLength()
);
Object coreMessage = tryParseCoreUdpMessage(data);
if (coreMessage instanceof HeartbeatMessage heartbeat) {
connectionManager.receiveHeartbeat(
heartbeat,
packet.getAddress()
);
return;
}
if (coreMessage instanceof GoodbyeMessage goodbye) {
connectionManager.receiveGoodbye(goodbye);
return;
}
if (coreMessage instanceof SessionInviteMessage invite) {
connectionManager.receiveSessionInvite(invite);
return;
}
pluginManager.handleMessage(data);
}
/** /**
* Tenta identificar os dados recebidos como uma mensagem de heartbeat. * Tenta identificar os dados recebidos como uma mensagem de heartbeat.
* *
@@ -224,7 +263,7 @@ public class SocketUDP extends Thread {
public void run() { public void run() {
try { try {
this.receive(); this.receive();
} catch (IOException | ClassNotFoundException ex) { } catch (IOException ex) {
Logger.getLogger(SocketUDP.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(SocketUDP.class.getName()).log(Level.SEVERE, null, ex);
} }
} }