diff --git a/shine-server-db/src/main/java/shine/db/MsgSubType.java b/shine-server-db/src/main/java/shine/db/MsgSubType.java index 92d121b..fd12967 100644 --- a/shine-server-db/src/main/java/shine/db/MsgSubType.java +++ b/shine-server-db/src/main/java/shine/db/MsgSubType.java @@ -42,14 +42,14 @@ public final class MsgSubType { public static final short CONNECTION_UNFRIEND = 11; /** Подписаться (follow). */ - public static final short CONNECTION_FOLLOW = 20; + public static final short CONNECTION_FOLLOW = 30; /** Отписаться (unfollow). */ - public static final short CONNECTION_UNFOLLOW = 21; - - /** Заблокировать. */ - public static final short CONNECTION_BLOCK = 30; - - /** Разблокировать. */ - public static final short CONNECTION_UNBLOCK = 31; + public static final short CONNECTION_UNFOLLOW = 31; +// +// /** Заблокировать. */ +// public static final short CONNECTION_BLOCK = 30; +// +// /** Разблокировать. */ +// public static final short CONNECTION_UNBLOCK = 31; } \ No newline at end of file diff --git a/shine-server-net-protocol/src/main/java/server/logic/ws_protocol/JSON/JsonHandlerRegistry.java b/shine-server-net-protocol/src/main/java/server/logic/ws_protocol/JSON/JsonHandlerRegistry.java index 8a5ec42..4f92271 100644 --- a/shine-server-net-protocol/src/main/java/server/logic/ws_protocol/JSON/JsonHandlerRegistry.java +++ b/shine-server-net-protocol/src/main/java/server/logic/ws_protocol/JSON/JsonHandlerRegistry.java @@ -23,52 +23,56 @@ import server.logic.ws_protocol.JSON.handlers.userParams.entyties.Net_GetUserPar import server.logic.ws_protocol.JSON.handlers.userParams.entyties.Net_ListUserParams_Request; import server.logic.ws_protocol.JSON.handlers.userParams.entyties.Net_UpsertUserParam_Request; +// !!! подставь реальные пакеты/имена, как у тебя в проекте: +import server.logic.ws_protocol.JSON.handlers.subscriptions.Net_GetSubscribedChannels_Handler; +import server.logic.ws_protocol.JSON.handlers.subscriptions.entyties.Net_GetSubscribedChannels_Request; + import java.util.Map; /** * JsonHandlerRegistry — единое место, где руками регистрируются * JSON-операции: op → handler и op → requestClass. - * - * Если нужно добавить новый запрос: - * 1) создаёшь класс NetXXXRequest / NetXXXResponse, - * 2) создаёшь JsonMessageHandler (NetXXXHandler), - * 3) добавляешь op в HANDLERS и REQUEST_TYPES. */ public final class JsonHandlerRegistry { - private static final Map HANDLERS = Map.of( - "RefreshSession", new Net_RefreshSession_Handler(), - "AddUser", new Net_AddUser_Handler(), - "AuthChallenge", new Net_AuthChallenge_Handler(), - "CreateAuthSession", new Net_CreateAuthSession__Handler(), - "CloseActiveSession", new Net_CloseActiveSession_Handler(), - "ListSessions", new Net_ListSessions_Handler(), - "AddBlock", new Net_AddBlock_Handler(), + // Map.of(...) поддерживает максимум 10 пар => используем Map.ofEntries(...) + private static final Map HANDLERS = Map.ofEntries( + Map.entry("RefreshSession", new Net_RefreshSession_Handler()), + Map.entry("AddUser", new Net_AddUser_Handler()), + Map.entry("AuthChallenge", new Net_AuthChallenge_Handler()), + Map.entry("CreateAuthSession", new Net_CreateAuthSession__Handler()), + Map.entry("CloseActiveSession", new Net_CloseActiveSession_Handler()), + Map.entry("ListSessions", new Net_ListSessions_Handler()), + Map.entry("AddBlock", new Net_AddBlock_Handler()), // --- userParams --- - "UpsertUserParam", new Net_UpsertUserParam_Handler(), - "GetUserParam", new Net_GetUserParam_Handler(), - "ListUserParams", new Net_ListUserParams_Handler() + Map.entry("UpsertUserParam", new Net_UpsertUserParam_Handler()), + Map.entry("GetUserParam", new Net_GetUserParam_Handler()), + Map.entry("ListUserParams", new Net_ListUserParams_Handler()), + + // --- subscriptions --- + Map.entry("ListSubscribedChannels", new Net_GetSubscribedChannels_Handler()) ); - private static final Map> REQUEST_TYPES = Map.of( - "RefreshSession", Net_RefreshSession_Request.class, - "AddUser", Net_AddUser_Request.class, - "AuthChallenge", Net_AuthChallenge_Request.class, - "CreateAuthSession", Net_CreateAuthSession_Request.class, - "CloseActiveSession", Net_CloseActiveSession_Request.class, - "ListSessions", Net_ListSessions_Request.class, - "AddBlock", Net_AddBlock_Request.class, + private static final Map> REQUEST_TYPES = Map.ofEntries( + Map.entry("RefreshSession", Net_RefreshSession_Request.class), + Map.entry("AddUser", Net_AddUser_Request.class), + Map.entry("AuthChallenge", Net_AuthChallenge_Request.class), + Map.entry("CreateAuthSession", Net_CreateAuthSession_Request.class), + Map.entry("CloseActiveSession", Net_CloseActiveSession_Request.class), + Map.entry("ListSessions", Net_ListSessions_Request.class), + Map.entry("AddBlock", Net_AddBlock_Request.class), // --- userParams --- - "UpsertUserParam", Net_UpsertUserParam_Request.class, - "GetUserParam", Net_GetUserParam_Request.class, - "ListUserParams", Net_ListUserParams_Request.class + Map.entry("UpsertUserParam", Net_UpsertUserParam_Request.class), + Map.entry("GetUserParam", Net_GetUserParam_Request.class), + Map.entry("ListUserParams", Net_ListUserParams_Request.class), + + // --- subscriptions --- + Map.entry("ListSubscribedChannels", Net_GetSubscribedChannels_Request.class) ); - private JsonHandlerRegistry() { - // utility - } + private JsonHandlerRegistry() { } public static Map getHandlers() { return HANDLERS; diff --git a/src/test/java/test/it/cases/IT_03_AddBlock_NoAuth.java b/src/test/java/test/it/cases/IT_03_AddBlock_NoAuth.java index 70355ad..1a01923 100644 --- a/src/test/java/test/it/cases/IT_03_AddBlock_NoAuth.java +++ b/src/test/java/test/it/cases/IT_03_AddBlock_NoAuth.java @@ -37,15 +37,24 @@ public class IT_03_AddBlock_NoAuth { String u1 = TestConfig.LOGIN(); String u2 = TestConfig.LOGIN2(); + String u3 = TestConfig.LOGIN3(); String bch1 = TestConfig.getBlockchainName(u1); String bch2 = TestConfig.getBlockchainName(u2); + String bch3 = TestConfig.getBlockchainName(u3); Duration t = Duration.ofSeconds(1); try (WsSession ws = WsSession.open()) { - if (TestConfig.DEBUG()) TestLog.titleBlock("IT_03: USER1=" + u1 + " bch=" + bch1 + " | USER2=" + u2 + " bch=" + bch2); + if (TestConfig.DEBUG()) { + TestLog.titleBlock( + "IT_03:\n" + + " USER1=" + u1 + " bch=" + bch1 + "\n" + + " USER2=" + u2 + " bch=" + bch2 + "\n" + + " USER3=" + u3 + " bch=" + bch3 + ); + } // USER1 ChainState st1 = new ChainState(); @@ -88,11 +97,33 @@ public class IT_03_AddBlock_NoAuth { sender2.send(new UserParamBody("Anya", "Amsterdam, Example street 10"), t); + // USER3 (нужен, чтобы u1 мог подписаться на существующий блокчейн) + ChainState st3 = new ChainState(); + AddBlockSender sender3 = new AddBlockSender(ws, st3, u3, bch3, TestConfig.getBlockchainPrivatKey(u3)); + + sender3.send(new HeaderBody(u3), t); + assertTrue(st3.hasHeader()); + + // ----------------------------------------------------------------- + // Подписки (как ты просил): + // - u1 follows u2 и u3 + // - u2 follows только u1 + // ----------------------------------------------------------------- + + // u1 -> follow u2 + sender1.send(new ConnectionBody(ConnectionBody.SUB_FOLLOW, u2, bch2, 0, new byte[32]), t); + + // u1 -> follow u3 + sender1.send(new ConnectionBody(ConnectionBody.SUB_FOLLOW, u3, bch3, 0, new byte[32]), t); + + // u2 -> follow u1 + sender2.send(new ConnectionBody(ConnectionBody.SUB_FOLLOW, u1, bch1, 0, new byte[32]), t); + + // (оставил твои friend/unfriend как было — но они уже не обязательны для подписок) sender2.send(new ConnectionBody(ConnectionBody.SUB_FRIEND, u1, bch1, 0, new byte[32]), t); sender1.send(new UserParamBody("Anna", "Gareeva"), t); sender1.send(new ConnectionBody(ConnectionBody.SUB_FRIEND, u2, bch2, 0, new byte[32]), t); - sender1.send(new ConnectionBody(ConnectionBody.SUB_FOLLOW, u2, bch2, 0, new byte[32]), t); sender2.send(new ConnectionBody(ConnectionBody.SUB_UNFRIEND, u1, bch1, 0, new byte[32]), t); diff --git a/src/test/java/test/it/runner/IT_RunAllMain.java b/src/test/java/test/it/runner/IT_RunAllMain.java index 07fccdc..8f770a6 100644 --- a/src/test/java/test/it/runner/IT_RunAllMain.java +++ b/src/test/java/test/it/runner/IT_RunAllMain.java @@ -4,6 +4,7 @@ import test.it.cases.IT_01_AddUser; import test.it.cases.IT_02_Sessions; import test.it.cases.IT_03_AddBlock_NoAuth; import test.it.cases.IT_04_UserParams_NoAuth; +import test.it.cases.IT_05_ListSubscribedChannels_200; import test.it.utils.log.TestLog; import java.util.ArrayList; @@ -17,7 +18,6 @@ public class IT_RunAllMain { public static void main(String[] args) { int failed = runAll(); - System.exit(failed); } public static int runAll() { @@ -31,6 +31,7 @@ public class IT_RunAllMain { String s2 = IT_02_Sessions.run(); summaries.add(s2); if (s2.contains("FAIL:")) failed++; String s3 = IT_03_AddBlock_NoAuth.run(); summaries.add(s3); if (s3.contains("FAIL:")) failed++; String s4 = IT_04_UserParams_NoAuth.run(); summaries.add(s4); if (s4.contains("FAIL:")) failed++; + String s5 = IT_05_ListSubscribedChannels_200.run(); summaries.add(s5); if (s5.contains("FAIL:")) failed++; TestLog.title("IT RUN RESULT (per test)"); for (String s : summaries) System.out.println(s); diff --git a/src/test/java/test/it/utils/json/JsonBuilders.java b/src/test/java/test/it/utils/json/JsonBuilders.java index 111d1de..0e3f19d 100644 --- a/src/test/java/test/it/utils/json/JsonBuilders.java +++ b/src/test/java/test/it/utils/json/JsonBuilders.java @@ -132,6 +132,20 @@ public final class JsonBuilders { """.formatted(requestId, sessionId, timeMs, signatureB64); } + // ---------------- ListSubscribedChannels ---------------- + + public static String listSubscribedChannels(String login) { + String requestId = TestIds.next("subs"); + return """ + { + "op": "ListSubscribedChannels", + "requestId": "%s", + "payload": { "login": "%s" } + } + """.formatted(requestId, login); + } + + /** * Подпись для режима AUTH_IN_PROGRESS: * preimage = "AUTHORIFICATED:" + timeMs + authNonce