fix(shell): normalizar IPv4 de peers no Windows
Evita IP IPv6-mapeado com zone id no campo de destino ao abrir conversa pela lista. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
8fe9bee453
commit
e0624403b2
10 files changed
+131
-47
No files matched your search
@@ -12,6 +12,7 @@ import pitiupi.chat.net.LegacyMpChatMessage;
|
||||
import pitiupi.control.ConnectionManager;
|
||||
import pitiupi.models.User;
|
||||
import pitiupi.presentation.shell.LocalNetworkInfo;
|
||||
import pitiupi.presentation.shell.PeerIpv4;
|
||||
import pitiupi.presentation.shell.LocalUserIdentity;
|
||||
import pitiupi.presentation.shell.PeerDraftPanel;
|
||||
import pitiupi.presentation.shell.PluginRoutingPanel;
|
||||
@@ -245,14 +246,7 @@ public class ChatPanel extends JPanel implements PrivateChatUiSink {
|
||||
}
|
||||
|
||||
private static String canonicalPeerIp(String ip) {
|
||||
if (ip == null || ip.isBlank()) {
|
||||
return "";
|
||||
}
|
||||
try {
|
||||
return InetAddress.getByName(ip.trim()).getHostAddress();
|
||||
} catch (Exception ex) {
|
||||
return ip.trim();
|
||||
}
|
||||
return PeerIpv4.normalize(ip);
|
||||
}
|
||||
|
||||
private void selectRoomSession() {
|
||||
@@ -275,7 +269,7 @@ public class ChatPanel extends JPanel implements PrivateChatUiSink {
|
||||
return;
|
||||
}
|
||||
peer.getInetAddress().ifPresent(addr ->
|
||||
openPeerTab(addr.getHostAddress(), peer.getDisplayName()));
|
||||
openPeerTab(PeerIpv4.fromInetAddress(addr), peer.getDisplayName()));
|
||||
}
|
||||
|
||||
public void enablePrivateTcpForPeer(UserPeerView peer) {
|
||||
@@ -415,7 +409,7 @@ public class ChatPanel extends JPanel implements PrivateChatUiSink {
|
||||
if (privateChatController != null) {
|
||||
privateChatController.openChat(user);
|
||||
}
|
||||
appendSystemLine(privateKey(user.getAddress().getHostAddress()),
|
||||
appendSystemLine(privateKey(PeerIpv4.fromInetAddress(user.getAddress())),
|
||||
"Canal TCP privado conectando… envie de novo em instantes.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import pitiupi.control.ConnectionManager;
|
||||
import pitiupi.models.User;
|
||||
import pitiupi.net.tcp.TcpConnection;
|
||||
import pitiupi.presentation.shell.LocalNetworkInfo;
|
||||
import pitiupi.presentation.shell.PeerIpv4;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@@ -29,14 +30,14 @@ public class PrivateChatController {
|
||||
}
|
||||
|
||||
private static String addressKey(TcpConnection connection) {
|
||||
return connection.getAddress().getHostAddress();
|
||||
return PeerIpv4.fromInetAddress(connection.getAddress());
|
||||
}
|
||||
|
||||
public void openChat(User user) {
|
||||
if (user == null || user.getAddress() == null) {
|
||||
return;
|
||||
}
|
||||
String address = user.getAddress().getHostAddress();
|
||||
String address = PeerIpv4.fromInetAddress(user.getAddress());
|
||||
if (connections.containsKey(address)) {
|
||||
if (uiSink != null) {
|
||||
uiSink.onPrivateChannelReady(address);
|
||||
@@ -77,7 +78,7 @@ public class PrivateChatController {
|
||||
if (user == null || user.getAddress() == null || text == null || text.isBlank()) {
|
||||
return false;
|
||||
}
|
||||
String address = user.getAddress().getHostAddress();
|
||||
String address = PeerIpv4.fromInetAddress(user.getAddress());
|
||||
TcpConnection connection = connections.get(address);
|
||||
if (connection == null) {
|
||||
return false;
|
||||
@@ -104,6 +105,6 @@ public class PrivateChatController {
|
||||
if (user == null || user.getAddress() == null) {
|
||||
return false;
|
||||
}
|
||||
return connections.containsKey(user.getAddress().getHostAddress());
|
||||
return connections.containsKey(PeerIpv4.fromInetAddress(user.getAddress()));
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import pitiupi.chat.net.ChatMessage;
|
||||
import pitiupi.chat.net.LegacyMpChatMessage;
|
||||
import pitiupi.control.ConnectionManager;
|
||||
import pitiupi.presentation.shell.LocalUserIdentity;
|
||||
import pitiupi.presentation.shell.PeerIpv4;
|
||||
import pitiupi.control.GuiManager;
|
||||
import pitiupi.models.Messages.Message;
|
||||
import pitiupi.models.Plugin;
|
||||
@@ -138,17 +139,17 @@ public class ChatPlugin extends Plugin implements PrivateChatHost {
|
||||
if (ip == null || ip.isBlank() || connectionManager == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
InetAddress address = InetAddress.getByName(ip);
|
||||
for (UserPeerView view : connectionManager.getPresenceService().listPeerViews()) {
|
||||
if (view.isSelf()) {
|
||||
continue;
|
||||
}
|
||||
if (view.getInetAddress().isPresent() && view.getInetAddress().get().equals(address)) {
|
||||
return view.getInstanceId();
|
||||
}
|
||||
String needle = PeerIpv4.normalize(ip);
|
||||
if (needle.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
for (UserPeerView view : connectionManager.getPresenceService().listPeerViews()) {
|
||||
if (view.isSelf()) {
|
||||
continue;
|
||||
}
|
||||
if (view.getInetAddress().map(PeerIpv4::fromInetAddress).orElse("").equals(needle)) {
|
||||
return view.getInstanceId();
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -166,7 +167,7 @@ public class ChatPlugin extends Plugin implements PrivateChatHost {
|
||||
return true;
|
||||
}
|
||||
privateChatController.receiveMessage(connection, legacy);
|
||||
String instanceId = peerInstanceIdForActivity(connection.getAddress().getHostAddress());
|
||||
String instanceId = peerInstanceIdForActivity(PeerIpv4.fromInetAddress(connection.getAddress()));
|
||||
if (instanceId != null) {
|
||||
connectionManager.getPeerActivityInbox().record(instanceId, getIdentifier(), "chat.private.tcp");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user