-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor StatSvc ip recording, fix #2349 #2351
base: dev
Are you sure you want to change the base?
Conversation
请添加单元测试,至少测试不需要网络请求的 ipv4 |
mirai-core/src/jvmBaseMain/kotlin/network/protocol/packet/login/StatSvc.kt
Outdated
Show resolved
Hide resolved
Fallback to resolve dns when testing
Using all instead of any
@@ -30,14 +30,15 @@ internal abstract class AbstractCommonNHTestWithSelector : | |||
overrideComponents[BotOfflineEventMonitor] = BotOfflineEventMonitorImpl() | |||
} | |||
|
|||
val conn = PlatformConn() | |||
val conn get() = PlatformConn(createAddress()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
by lazy?
@@ -131,6 +131,16 @@ internal open class NettyNetworkHandler( | |||
return contextResult.await() | |||
} | |||
|
|||
override fun io.netty.channel.Channel.getConnectedIP(): Long = this.remoteAddress().let { address -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为什么要有这个lambda?
0L | ||
} | ||
} | ||
}.invoke() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
创建lambda立即invoke只会增加复杂度
@@ -51,7 +57,16 @@ internal actual abstract class AbstractCommonNHTest actual constructor() : | |||
} | |||
} | |||
|
|||
actual val conn: PlatformConn = NettyNHTestChannel() | |||
actual val conn: PlatformConn get() = PlatformConn(address = createAddress()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
by lazy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JVM那边的测试也是get() 而且这里是创建连接才会去get这个 get()这里应该没问题
@@ -32,8 +37,22 @@ internal actual abstract class AbstractCommonNHTest actual constructor() : | |||
protected actual fun removeOutgoingPacketEncoder() { | |||
} | |||
|
|||
actual val conn: PlatformConn = PlatformConn() | |||
actual val conn: PlatformConn get() = PlatformConn(createAddress()) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
by lazy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JVM那边的测试也是get() 而且这里是创建连接才会去get这个 get()这里应该没问题
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
属性get有副作用而且每次都创建新实例是不好的
uOldSSOIp = if (lastDisconnectedIP in 1..2) { | ||
-lastDisconnectedIP | ||
} else { | ||
lastDisconnectedIP | ||
} | ||
uNewSSOIp = if (lastConnectedIP in 1..2) { | ||
-lastDisconnectedIP | ||
} else { | ||
lastConnectedIP | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这部分应该在提供这个 ip 的地方处理
@@ -24,6 +24,7 @@ import kotlin.jvm.JvmName | |||
*/ | |||
internal expect class PlatformSocket : Closeable, HighwayProtocolChannel { | |||
val isOpen: Boolean | |||
val connectedIp: Long |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
给特殊意义值留下注释
actual val connectedIp: Long | ||
get() = if (isOpen) { | ||
sockets.socket_get_connected_ip(socket).toLong() | ||
} else { | ||
0L | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
应该在这里就直接处理特殊值 (0, 1, ....) 的情况(即切换回负数), 而不是交给外部
Why? This should not be applied without special reasons. |
Because in my test it returning ipv6 first and cause connect failed lol |
You should recheck your network environment first. Even if there is a bug, it’s not wise to disable Ipv6 rather than fixing the bug.
|
But I just have ipv6 in my local network and could not use ipv6 to connect, it's the most user environment (in China), and currently tencent just provide ipv4 address and a domain, in this case, original native code will be resulted in could not init connection and retrying (we just have this domain in ip list when first init) |
If you want to use ipv6 anyway, linux code need to refactor as well since it just support ipv4, and both need to impl a dns query then use a loop to try every ip |
I don't think so, at least almost all ISPs in maintain China begin to distribute IPv6 addresses.
This is a powerful point. I'll check it later.
No, the origin code creates a dual-stack socket (via
I don't think so. |
I’ve tried to disable IPv4 totally and then open Mobile QQ, it works well.
I think we need to dig into it.
|
我觉得可以先完善 v4, 之后再考虑 v6 |
I'm the beginner for C language, so feel free to let me know if there have any wrong here : D
Changes: