Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
70f421ae
Commit
70f421ae
authored
Apr 23, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix long message, unify logs
parent
d584b765
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
45 deletions
+33
-45
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.common.kt
...n/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.common.kt
+13
-35
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/GroupImpl.kt
...ain/kotlin/net/mamoe/mirai/qqandroid/contact/GroupImpl.kt
+1
-1
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/highway/HighwayHelper.kt
...et/mamoe/mirai/qqandroid/network/highway/HighwayHelper.kt
+19
-9
No files found.
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.common.kt
View file @
70f421ae
...
@@ -20,7 +20,6 @@ import kotlinx.coroutines.CoroutineName
...
@@ -20,7 +20,6 @@ import kotlinx.coroutines.CoroutineName
import
kotlinx.coroutines.async
import
kotlinx.coroutines.async
import
kotlinx.coroutines.io.ByteReadChannel
import
kotlinx.coroutines.io.ByteReadChannel
import
kotlinx.coroutines.withContext
import
kotlinx.coroutines.withContext
import
kotlinx.coroutines.withTimeoutOrNull
import
kotlinx.serialization.UnstableDefault
import
kotlinx.serialization.UnstableDefault
import
kotlinx.serialization.json.Json
import
kotlinx.serialization.json.Json
import
kotlinx.serialization.json.JsonConfiguration
import
kotlinx.serialization.json.JsonConfiguration
...
@@ -50,8 +49,10 @@ import net.mamoe.mirai.qqandroid.network.protocol.data.proto.ImMsgBody
...
@@ -50,8 +49,10 @@ import net.mamoe.mirai.qqandroid.network.protocol.data.proto.ImMsgBody
import
net.mamoe.mirai.qqandroid.network.protocol.data.proto.LongMsg
import
net.mamoe.mirai.qqandroid.network.protocol.data.proto.LongMsg
import
net.mamoe.mirai.qqandroid.network.protocol.packet.chat.*
import
net.mamoe.mirai.qqandroid.network.protocol.packet.chat.*
import
net.mamoe.mirai.qqandroid.network.protocol.packet.list.FriendList
import
net.mamoe.mirai.qqandroid.network.protocol.packet.list.FriendList
import
net.mamoe.mirai.qqandroid.utils.*
import
net.mamoe.mirai.qqandroid.utils.MiraiPlatformUtils
import
net.mamoe.mirai.qqandroid.utils.encodeToString
import
net.mamoe.mirai.qqandroid.utils.io.serialization.toByteArray
import
net.mamoe.mirai.qqandroid.utils.io.serialization.toByteArray
import
net.mamoe.mirai.qqandroid.utils.toReadPacket
import
net.mamoe.mirai.utils.*
import
net.mamoe.mirai.utils.*
import
kotlin.collections.asSequence
import
kotlin.collections.asSequence
import
kotlin.contracts.ExperimentalContracts
import
kotlin.contracts.ExperimentalContracts
...
@@ -606,39 +607,16 @@ internal abstract class QQAndroidBotBase constructor(
...
@@ -606,39 +607,16 @@ internal abstract class QQAndroidBotBase constructor(
)
)
).
toByteArray
(
LongMsg
.
ReqBody
.
serializer
())
).
toByteArray
(
LongMsg
.
ReqBody
.
serializer
())
var
exception
:
Throwable
?
=
null
HighwayHelper
.
uploadImageToServers
(
bot
,
val
success
=
response
.
proto
.
uint32UpIp
.
zip
(
response
.
proto
.
uint32UpPort
).
any
{
(
ip
,
port
)
->
response
.
proto
.
uint32UpIp
.
zip
(
response
.
proto
.
uint32UpPort
),
kotlin
.
runCatching
{
response
.
proto
.
msgSig
,
withTimeoutOrNull
((
body
.
size
*
1000L
/
1024
/
10
).
coerceAtLeast
(
5000L
))
{
MiraiPlatformUtils
.
md5
(
body
),
network
.
logger
.
verbose
{
"[Highway] Uploading group long message#$sequenceId to ${ip.toIpV4AddressString()}:$port: size=${body.size}"
}
body
.
toReadPacket
(),
HighwayHelper
.
uploadImage
(
body
.
size
.
toLongUnsigned
(),
client
,
"group long message"
,
serverIp
=
ip
.
toIpV4AddressString
(),
27
serverPort
=
port
,
)
ticket
=
response
.
proto
.
msgSig
,
// 104
imageInput
=
body
.
toReadPacket
(),
inputSize
=
body
.
size
,
fileMd5
=
MiraiPlatformUtils
.
md5
(
body
),
commandId
=
27
// long msg
)
network
.
logger
.
verbose
{
"[Highway] Uploading group long message#$sequenceId: succeed"
}
true
}
?:
kotlin
.
run
{
network
.
logger
.
verbose
{
"[Highway] Uploading group long message: timeout, retrying next server"
}
false
}
}.
getOrElse
{
exception
?.
addSuppressedMirai
(
it
)
exception
=
it
false
}
}
if
(!
success
)
{
throw
IllegalStateException
(
"cannot upload group long message, failed on all servers."
,
exception
)
}
}
}
}
}
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/GroupImpl.kt
View file @
70f421ae
...
@@ -416,7 +416,7 @@ internal class GroupImpl(
...
@@ -416,7 +416,7 @@ internal class GroupImpl(
response
.
uploadIpList
.
zip
(
response
.
uploadPortList
),
response
.
uploadIpList
.
zip
(
response
.
uploadPortList
),
response
.
uKey
,
response
.
uKey
,
image
,
image
,
kind
=
"group"
,
kind
=
"group
image
"
,
commandId
=
2
commandId
=
2
)
)
val
resourceId
=
image
.
calculateImageResourceId
()
val
resourceId
=
image
.
calculateImageResourceId
()
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/highway/HighwayHelper.kt
View file @
70f421ae
...
@@ -102,23 +102,33 @@ internal suspend fun HttpClient.postImage(
...
@@ -102,23 +102,33 @@ internal suspend fun HttpClient.postImage(
@OptIn
(
MiraiInternalAPI
::
class
,
InternalSerializationApi
::
class
)
@OptIn
(
MiraiInternalAPI
::
class
,
InternalSerializationApi
::
class
)
internal
object
HighwayHelper
{
internal
object
HighwayHelper
{
suspend
fun
uploadImageToServers
(
bot
:
QQAndroidBot
,
servers
:
List
<
Pair
<
Int
,
Int
>>,
uKey
:
ByteArray
,
image
:
ExternalImage
,
kind
:
String
,
commandId
:
Int
)
=
uploadImageToServers
(
bot
,
servers
,
uKey
,
image
.
md5
,
image
.
input
,
image
.
inputSize
,
kind
,
commandId
)
@OptIn
(
ExperimentalTime
::
class
)
@OptIn
(
ExperimentalTime
::
class
)
suspend
fun
uploadImageToServers
(
suspend
fun
uploadImageToServers
(
bot
:
QQAndroidBot
,
bot
:
QQAndroidBot
,
servers
:
List
<
Pair
<
Int
,
Int
>>,
servers
:
List
<
Pair
<
Int
,
Int
>>,
uKey
:
ByteArray
,
uKey
:
ByteArray
,
image
:
ExternalImage
,
md5
:
ByteArray
,
input
:
Any
,
inputSize
:
Long
,
kind
:
String
,
kind
:
String
,
commandId
:
Int
commandId
:
Int
)
=
servers
.
retryWithServers
(
)
=
servers
.
retryWithServers
(
(
i
mage
.
i
nputSize
*
1000
/
1024
/
10
).
coerceAtLeast
(
5000
),
(
inputSize
*
1000
/
1024
/
10
).
coerceAtLeast
(
5000
),
onFail
=
{
onFail
=
{
throw
IllegalStateException
(
"cannot upload $kind
image
, failed on all servers."
,
it
)
throw
IllegalStateException
(
"cannot upload $kind, failed on all servers."
,
it
)
}
}
)
{
ip
,
port
->
)
{
ip
,
port
->
bot
.
network
.
logger
.
verbose
{
bot
.
network
.
logger
.
verbose
{
"[Highway] Uploading $kind
image to ${ip}:$port, size=${image.
inputSize / 1024} KiB"
"[Highway] Uploading $kind
to ${ip}:$port, size=${
inputSize / 1024} KiB"
}
}
val
time
=
measureTime
{
val
time
=
measureTime
{
...
@@ -126,21 +136,21 @@ internal object HighwayHelper {
...
@@ -126,21 +136,21 @@ internal object HighwayHelper {
client
=
bot
.
client
,
client
=
bot
.
client
,
serverIp
=
ip
,
serverIp
=
ip
,
serverPort
=
port
,
serverPort
=
port
,
imageInput
=
i
mage
.
i
nput
,
imageInput
=
input
,
inputSize
=
i
mage
.
i
nputSize
.
toInt
(),
inputSize
=
inputSize
.
toInt
(),
fileMd5
=
image
.
md5
,
fileMd5
=
md5
,
ticket
=
uKey
,
ticket
=
uKey
,
commandId
=
commandId
commandId
=
commandId
)
)
}
}
bot
.
network
.
logger
.
verbose
{
bot
.
network
.
logger
.
verbose
{
"[Highway] Uploading $kind
image: succeed at ${(image.
inputSize.toDouble() / 1024 / time.inSeconds).roundToInt()} KiB/s"
"[Highway] Uploading $kind
: succeed at ${(
inputSize.toDouble() / 1024 / time.inSeconds).roundToInt()} KiB/s"
}
}
}
}
@OptIn
(
InternalCoroutinesApi
::
class
)
@OptIn
(
InternalCoroutinesApi
::
class
)
private
suspend
fun
uploadImage
(
internal
suspend
fun
uploadImage
(
client
:
QQAndroidClient
,
client
:
QQAndroidClient
,
serverIp
:
String
,
serverIp
:
String
,
serverPort
:
Int
,
serverPort
:
Int
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment