Commit Graph

2762 Commits

Author SHA1 Message Date
Him188
ddcac473dd Improve logging on updating account secrets 2021-07-05 17:50:38 +08:00
sandtechnology
b7869888f0
StatSvc.Register: Provide SSO Ip and correct logic (#1240)
* StatSvc.Register: Provide SSO Ip and correct logic

* Remove unnessacy launch

Co-authored-by: Him188 <Him188@mamoe.net>

* Test for last polled ip

* Normal login test for last ip

* Fix test failed and remove debug code

* Fix unit test and build

* Optimize pollCurrent and pollAny method

* Use uOldSSOIp and uNewSSOIp only when protocol is PHONE

* Fix bug in toIpV4Long

* Fix new line in NettyBotNormalLoginTest.kt

* Using Inet4Address and toInt method for toIpV4Long

* Return Unsigned Long for toIpV4Long

* Remove unnessacy synchronized annotation

Co-authored-by: Him188 <Him188@mamoe.net>

* Using createAddress method instead of address

* Moving lastDisconnectedIp and lastConnectedIp to Server
List

* Fix build

* Fix build and remove empty line

* Keeping naming consistent

* Use bot.components instead of overrideComponents

Co-authored-by: Him188 <Him188@mamoe.net>

* Revert overrideComponents changes and add comment for overrideComponents

Co-authored-by: Him188 <Him188@mamoe.net>
2021-07-03 22:04:49 +08:00
Him188
2713127466 Fix reconnection on Heartbeat timeout: add PacketTimeoutException 2021-07-03 21:57:12 +08:00
Him188
7b42fc6888 Fix recalling friend message, fix #1293 2021-07-02 22:36:24 +08:00
Him188
6b18a6fea9 Improve PbMessageSvc.PbMsgWithDraw logging, helps #1293 2021-07-02 22:18:15 +08:00
Him188
ec5ad17ac4 Improve ForceOfflineException.message: use canonical message tips 2021-07-02 21:43:48 +08:00
Him188
8647d38b34 Add MessageReceiptTest for #1371 2021-07-02 21:06:31 +08:00
Him188
a59d7208cb Add getMiraiImpl to replace direct calls of MiraiImpl.INSTANCE 2021-07-02 21:06:31 +08:00
Him188
91a9e63877 Do light refine after constructing MessageReceipt, fix #1371 2021-07-02 21:06:31 +08:00
Karlatemp
a4b62b0909
Voice serialization (#1368)
* Voice serialization

* Implement `hashCode` and `equals` for `Voice`

* Update test

* Update test

* Add note of `PttMessage.pttInternalInstance`

* Fix logic of `Voice.equals`
2021-07-02 12:10:20 +08:00
Him188
5aae46218f Do not throw exception from PacketCodec but log with CoroutineExceptionHandler 2021-07-02 01:18:40 +08:00
Him188
b90f86258c Add property recoverable to HeartbeatFailedException, to control recoverability.
Fix `SelectorRecoveryTest`
2021-07-02 01:18:40 +08:00
Him188
adc39a93b5 Update copyright 2021-07-02 00:39:10 +08:00
Him188
b9eb654a51 Reformat and cleanup code 2021-07-02 00:39:10 +08:00
Him188
d114d0a2e6 Optimize BotInitProcessor and add tests 2021-07-02 00:39:10 +08:00
Him188
b78c276aef ChunkedFlowSession: Ensure channel is closed on completion 2021-07-02 00:39:10 +08:00
Him188
fa9d236949 Avoid using TopLevel logger in tests 2021-07-02 00:39:10 +08:00
Him188
f379a617fd NetworkHandlerSupport: catch all exceptions in coroutine scope and direct it to network logger 2021-07-02 00:39:10 +08:00
Him188
6012f33574 Add selector logging, helps #1361 2021-07-02 00:39:10 +08:00
Him188
4d3a9e7cc5 Add SynchronizedStdoutLogger for tests 2021-07-01 11:06:58 +08:00
Him188
0d339c7303 Remove redundant suspension in BotOfflineEventMonitorImpl 2021-06-30 23:01:42 +08:00
Him188
e10155a7b3 AbstractKeepAliveNetworkHandlerSelector do not yield() but check for cancellation manually. 2021-06-30 23:01:22 +08:00
Him188
c4d129542f Unwrap CancellationException on JobAttachStateObserver.stateChanged0 2021-06-29 23:10:06 +08:00
Him188
f1bb7c566f Add generic type to SelectorNetworkHandler, improve test framework:
- Make `AbstractRealNetworkHandlerTest` sealed with subtypes;
  - `AbstractNettyNHTest`
  - `AbstractNettyNHTestWithSelector`
- Set `mirai.event.launch.undispatched` to `true` for network tests
- Use real `BotOfflineEventMonitor` in tests with selector
2021-06-29 22:47:56 +08:00
sandtechnology
2ce549e56f
Fix #1322, remove redundant cookie (#1372)
* Fix #1322, removed useless parms

* Add missed perms

* Remove redundant cookie
2021-06-28 19:19:18 +08:00
Karlatemp
eb5c7414d7
Add hashCode and equals for Image, close #1302 2021-06-26 16:29:40 +08:00
Karlatemp
f7170f2052
Delete unused internal AbstractImage 2021-06-26 16:17:53 +08:00
Karlatemp
ae54a5fb41
Private voice support (#1310)
* Support voice for private messaging

* typo

* Add extension functions for `uploadAsVoice`; Update KDocs

* Update KDoc

* Update error message

* Fix `C2CPttStoreBDH` error

* Deprecated `ExternalResource.uploadAsVoice(Contact): Voice`

* Update mirai-core-api/src/commonMain/kotlin/utils/ExternalResource.kt

* apiDump

Co-authored-by: Him188 <Him188@mamoe.net>
2021-06-26 10:02:23 +08:00
sandtechnology
d349c19c2e
StatSvc.SimpleGet: Decode the resp (#1241)
* StatSvc.SimpleGet: Decode the resp

* Close network on `StatSvc.SimpleGet.Response.Error`

* Use new `IncomingPacket`

Co-authored-by: Him188 <Him188@mamoe.net>
2021-06-25 20:29:28 +08:00
Him188
ce4373a322 Use Either for IncomingPacket.result 2021-06-25 20:11:41 +08:00
Him188
11ffb324c9 Add Either 2021-06-25 20:05:28 +08:00
Him188
b02fa15b33 Broadcast BotReloginEvent stably 2021-06-24 01:04:39 +08:00
Noire
b8de3f77ff
GroupAnnoucement (#1141)
* Add more comment about GroupAnnouncement.kt

* Edit comment about GroupAnnouncement.kt
Provide experimental api

* Api Dump

* After review

* Change to interface and API dump

* More change

* More change

* More more change

* Some change

* api dump

* Fix name

* Redesign Announcement public api

* Edit comment about GroupAnnouncement.kt
Provide experimental api

* After review

* Change to interface and API dump

* More change

* Modify to extension fun

* Fix sendAnnouncement and change place

* Change Group.deleteAnnouncement to group companion

* fix publish

* Api dump

* Reformat code

* Add `@since 2.7`

* Fix build

Co-authored-by: Him188 <Him188@mamoe.net>
2021-06-24 00:59:53 +08:00
Him188
a8dbd761eb Use start=UNDISPATCHED in launchRecovery 2021-06-24 00:42:57 +08:00
Him188
47f1ae8134 Enable tests NettyHandlerEventTest #1311 2021-06-23 15:44:52 +08:00
Him188
2e47740b1b Move setState from coroutine scope completion handler to network.close, fix #1311 2021-06-23 15:44:52 +08:00
Him188
8d4eb45386 Rearrange functions in NettyNetworkHandler 2021-06-23 15:44:52 +08:00
sandtechnology
636584cdd1
ECDH: Replacing old curve, thanks to MiraiGo (#1237)
* ECDH: Replacing old curve, thanks to MiraiGo

* Move ecdhWithPublicKey to EcdhInitialPublicKeyUpdater

* Making ECDHInitialPublicKey internal

* Remove useless log

* Improve message

Co-authored-by: Him188 <Him188@mamoe.net>

Co-authored-by: Him188 <Him188@mamoe.net>
2021-06-23 14:59:12 +08:00
sandtechnology
ad7f95d0f0
Fix #1192, request admin when loading groups (#1257)
* Fix #1192, request admin when loading groups

* Improve message

Co-authored-by: Karlatemp <karlatemp@vip.qq.com>

Co-authored-by: Karlatemp <karlatemp@vip.qq.com>
2021-06-23 14:58:56 +08:00
Karlatemp
509be910c0
Avoid resource leak 2021-06-22 18:14:29 +08:00
Karlatemp
d1fdddf9e6
Break network when received LoginFailedException; fix #1352 2021-06-22 13:37:54 +08:00
Him188
f2ca8e1eff Revert "Fix kt compiler errors (#1159)"
This reverts commit b227f719
2021-06-19 23:58:27 +08:00
Him188
c37457cafb Cleanup and move local serializable classes to top-level 2021-06-19 18:28:21 +08:00
Him188
813ef2b1e6 Remove redundant tests 2021-06-19 17:41:32 +08:00
Him188
b4b25be626 Simplify setState 2021-06-19 17:16:07 +08:00
Him188
f229757395 Redesign BotInitProcessor to adjust force offline adjacently after login 2021-06-19 15:20:49 +08:00
Him188
3cc0973edd Revert "Add PacketInterceptor"
This reverts commit 04656d7a
2021-06-19 14:52:26 +08:00
Him188
d654e95f0f Revert "Fix fast login"
This reverts commit 77e5e91f
2021-06-19 14:52:23 +08:00
Karlatemp
77e5e91fc4
Fix fast login 2021-06-19 02:30:06 +08:00
Karlatemp
04656d7a03
Add PacketInterceptor 2021-06-19 02:28:16 +08:00
Karlatemp
e816755414
Fix state switching when switching to CLOSED 2021-06-19 02:26:47 +08:00
Karlatemp
627e9baa6f
Fix NettyNetworkHandler debug message 2021-06-19 02:25:38 +08:00
Karlatemp
8b5b76e32e
Run BaseStateImpl.setState with lock 2021-06-19 02:24:59 +08:00
Him188
b33d1edf03 Add SingleEntrantLock 2021-06-19 00:29:54 +08:00
Him188
833c9d2c97 Do not turn state into Connecting in handlePipelineException 2021-06-19 00:06:14 +08:00
Him188
faed38da9e Do not set state to CLOSED multiple times on close 2021-06-19 00:06:14 +08:00
Him188
99d232efe8 Remove redundant synchronization in NetworkHandlerSupport.setState 2021-06-19 00:05:50 +08:00
Him188
eba6706b47 Allow to change whether LoggingStateObserver is enabled in runtime 2021-06-19 00:04:39 +08:00
Him188
997c3ea2cf Remove SsoProcessor.createObserverChain 2021-06-19 00:04:32 +08:00
Him188
b8b8cb1fad Make LoggingStateObserver into use 2021-06-19 00:04:24 +08:00
Him188
44bfe3dbb6 Make NetworkHandlerFactory fun interface 2021-06-19 00:04:22 +08:00
Him188
c6d9825cf6 Add name to StateObverse 2021-06-19 00:04:20 +08:00
Him188
fbf7142eaf Improve performance of StateObserver.chainOfNotNull 2021-06-19 00:04:10 +08:00
Him188
f1d58c4953 Fix CombinedStateObserver.beforeStateChanged 2021-06-19 00:04:05 +08:00
Him188
951f3b2bc4 Reduce CombinedStateObserver hierarchy: use List 2021-06-19 00:03:45 +08:00
sandtechnology
48f9ca0d48
Fix #1334, update pb and fix private image upload issue (#1335)
* Fix #1334, update pb and fix private image upload issue

* Keeping consistent in annotation

* Restore old comment

* Let extendinfo default to null
2021-06-19 00:00:16 +08:00
Him188
4d10338815 Do not add BotOfflineEventMonitor in SetStateTest 2021-06-17 00:20:41 +08:00
Him188
5efced6167 Move RECONNECT_DELAY to AbstractKeepAliveNetworkHandlerSelector and set it to 0 in tests 2021-06-16 19:49:17 +08:00
Him188
cde13062d9 Ensure network closed on initialization failure 2021-06-16 19:42:58 +08:00
Him188
fc477e0122 Do not wrap exception into ISE on reaching max attempts 2021-06-16 17:26:57 +08:00
Him188
a38f24cbe5 Redesign connection maintenance mechanism:
Reconnection is directed by `BotOfflineEvent`.

### Event Broadcasting

- PacketFactory `MessageSvcPushForceOffline` closes network with `ForceOfflineException`.
 - `network.close(cause)` pass the cause to state observer from `QQAndroidBot.stateObserverChain`, the observer broadcasts as follows:
   - Nothing if `cause` is `ForceOfflineException` or `BotClosedByEvent`(which is broadcast by user)
   - `BotOfflineEvent.Dropped` if cause is NetworkException and is recoverable(which is from Netty handlers)
   - `BotOfflineEvent.Force` if cause is `ForceOfflineException` is from the factory mentioned above.
   - `BotOfflineEvent.Active` otherwise(any other unexpected exceptions considered as an error)

### Deciding whether to reconnect

User can listen and change `BotOfflineEvent.reconnect` to decide. Default values are determined by `BotConfiguration`.

### Event listening

- Component `BotOfflineEventMonitor` listens `BotOfflineEvent`, logs the event for users, and launches a coroutine to do `network.resumeConnection` to notify the selector to renew an instance.
- `BotOnlineWatchdog` in `SelectorNetworkHandler` is removed.
- Selector now handles `maxAttempts` correctly in such a way that `awaitResumeInstance` does not throw exception until maximum attempts reached.
- On every attempt, new exceptions are logged to provide debugging information, and further duplications are ignored.
2021-06-16 16:58:20 +08:00
Him188
45ba713f73 Optimize HeartbeatFailedException.toString: show information of its cause 2021-06-16 03:09:21 +08:00
Him188
ab7c49a0d5 Remove log in BotClientHolderImpl 2021-06-16 03:06:54 +08:00
Him188
b219ba986e Review network ComponentStorage framework and improve connection logics, support reconnection on force offline (closes #1330, close #1331), and on bad network.
- Remove `FactoryKeepAliveNetworkHandlerSelector` and add `KeepAliveNetworkHandlerSelector`;
- Review the storage of `QQAndroidBotClient`, extract it as a `BotClientHolder`;
- Introduce bot-level components that lasts with the lifecycle of `Bot`, and network-level components accordingly;
- Dynamically re-create the context given to `NetworkHandler` in selector, to use network-level components, including `BotClientHolder`, that allows a simple reinitialization of `BotClient`;
- Handles the situation when physical network broken on logging in, giving a hint to user and halts the log-in process and transfer the responsibility of reconnecting to selector;
- Send logout only in `Bot.close` (manual close).
2021-06-16 03:00:50 +08:00
Him188
e65593b2af Add BeforeStateChangedObserver 2021-06-16 02:37:06 +08:00
Him188
23c1a67479 Add naming notes for StatSvc.Register in logging 2021-06-16 02:29:05 +08:00
Him188
ad4f7a6232 Show OutgoingPacket.displayName in logging 2021-06-16 02:28:51 +08:00
Him188
24ac4ffa95 Add ConcurrentComponentStorage builder 2021-06-16 01:52:42 +08:00
Him188
e6119e6301 Throw NoSuchComponentException with full details in CombinedComponentStorage.get 2021-06-16 01:52:27 +08:00
Him188
9933fab4c5 Add ComponentStorage?.withPrimary 2021-06-16 01:51:50 +08:00
Him188
f4ec905aff Make CombinedStateObserver.toString more readable 2021-06-16 01:51:26 +08:00
Him188
750ab0db37 Fix StackOverflowError on calling bot.client in tests with TestSsoProcessor, fix #1332 2021-06-15 20:47:50 +08:00
Him188
bebb786b9a Fix build 2021-06-13 11:10:12 +08:00
Him188
c9f98e46d7 Implement heartbeat periods and timeouts correctly, #1255 2021-06-13 10:59:11 +08:00
Him188
43b13d158f Implement HeartbeatStrategy, #1226 2021-06-13 10:50:55 +08:00
Karlatemp
e9d9d56489
Avoid network congestion 2021-06-11 21:19:35 +08:00
Karlatemp
05a8419fb7
Fix internal error in uploading private images; fix #1317 2021-06-10 22:49:24 +08:00
Him188
1e2ab736c2 Use bot.closeAndJoin() in tests 2021-06-08 17:13:37 +08:00
Him188
81258488cb Check isActive in BotOnlineWatchdog 2021-06-08 17:13:25 +08:00
Him188
300882ea18 Redesign ComponentStorage initialization for clearer tests 2021-06-08 17:13:15 +08:00
Him188
f9da72c136 Convert DEFAULT_BLACKLIST to function and initialize the immutable set only once 2021-06-08 16:16:01 +08:00
Him188
65a3ffc147 Rename ComponentScope.plus to .withFallback 2021-06-08 16:14:23 +08:00
Him188
c8def70594 Add bot.job as parent of NetworkHandlerSupport 2021-06-08 16:14:23 +08:00
Him188
5f7f350eb5 Close PacketDecodePipeline.channel on scope closure 2021-06-08 16:14:23 +08:00
Him188
038be54444 Remote pcap4j from jvmTest 2021-06-08 16:14:23 +08:00
Him188
19bc781854 Add kotlinx-coroutines-debug to jvmTest 2021-06-08 16:14:23 +08:00
Him188
ad3bd4cc0d Stop BotOnlineWatchdog if bot is closed 2021-06-08 12:19:05 +08:00
Him188
54a78313c8 Improve logging on exceptions and correctly handle CancellationException when Bot.close is invoked. 2021-06-08 12:18:40 +08:00
Him188
3e8fc8e1ec Do not pass failed IncomingPacket to PacketFactorys 2021-06-08 12:16:26 +08:00
Him188
725b502d9e Add notes for blacklist 2021-06-08 12:04:54 +08:00