Rename Bob to Bobik

- rename Repository vNode
- cluster topology: better vnodes lookup
This commit is contained in:
djmil 2023-10-02 11:23:16 +02:00
parent d58a89e3b3
commit 07ce05bf01
8 changed files with 67 additions and 24 deletions

View File

@ -5,7 +5,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.UUID;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -25,7 +24,7 @@ public class GameBoardTests {
HoldingIdentityResolver holdingIdentityResolver; HoldingIdentityResolver holdingIdentityResolver;
final String whitePlayerName = "alice"; final String whitePlayerName = "alice";
final String blackPlayerName = "bob"; final String blackPlayerName = "bobik";
final static Stone WHITE_MAN = new Stone(Stone.Color.WHITE, Stone.Type.MAN); final static Stone WHITE_MAN = new Stone(Stone.Color.WHITE, Stone.Type.MAN);
final static Stone WHITE_KING = new Stone(Stone.Color.WHITE, Stone.Type.KING); final static Stone WHITE_KING = new Stone(Stone.Color.WHITE, Stone.Type.KING);

View File

@ -21,8 +21,8 @@ public class GameProposalTests {
@Autowired @Autowired
HoldingIdentityResolver holdingIdentityResolver; HoldingIdentityResolver holdingIdentityResolver;
final String issuer = "alice"; final String issuer = "alice";
final String acquier = "bob"; final String acquier = "bobik";
final Stone.Color acquierColor = Stone.Color.WHITE; final Stone.Color acquierColor = Stone.Color.WHITE;
@Test @Test

View File

@ -8,7 +8,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import djmil.cordacheckers.cordaclient.dao.GameState; import djmil.cordacheckers.cordaclient.dao.GameState;
import djmil.cordacheckers.cordaclient.dao.Stone;
import djmil.cordacheckers.user.HoldingIdentityResolver; import djmil.cordacheckers.user.HoldingIdentityResolver;
@SpringBootTest @SpringBootTest
@ -19,22 +18,23 @@ public class GameStateTests {
@Autowired @Autowired
HoldingIdentityResolver holdingIdentityResolver; HoldingIdentityResolver holdingIdentityResolver;
final String issuer = "alice"; final String player1 = "alice";
final String acquier = "bob"; final String player2 = "bobik";
final Stone.Color acquierColor = Stone.Color.WHITE;
@Test @Test
void testList() { void testList() {
List<GameState> gsList = cordaClient.gameStateList( final var hiPlayer1 = holdingIdentityResolver.getByUsername(player1);
holdingIdentityResolver.getByUsername("bob"));
List<GameState> gsList = cordaClient.gameStateList(hiPlayer1);
System.out.println(gsList); System.out.println(gsList);
} }
@Test @Test
void testGet() { void testGet() {
GameState gameStateView = cordaClient.gameStateGet( final var hiPlayer2 = holdingIdentityResolver.getByUsername(player2);
holdingIdentityResolver.getByUsername("bob"),
GameState gameStateView = cordaClient.gameStateGet(hiPlayer2,
UUID.fromString("cf357d0a-8f64-4599-b9b5-d263163812d4") UUID.fromString("cf357d0a-8f64-4599-b9b5-d263163812d4")
); );

View File

@ -21,6 +21,9 @@ public class RankingTests {
@Autowired @Autowired
HoldingIdentityResolver holdingIdentityResolver; HoldingIdentityResolver holdingIdentityResolver;
final String player1 = "kumar";
final String player2 = "bobik";
@Test @Test
void testGlobalRanking() { void testGlobalRanking() {
final var hiCustodian = holdingIdentityResolver.getCustodian(); final var hiCustodian = holdingIdentityResolver.getCustodian();
@ -28,8 +31,8 @@ public class RankingTests {
final List<Rank> liderboard1 = cordaClient.fetchRanking(hiCustodian); final List<Rank> liderboard1 = cordaClient.fetchRanking(hiCustodian);
final var hiWinner = holdingIdentityResolver.getByUsername("Charlie"); final var hiWinner = holdingIdentityResolver.getByUsername(player1);
final var hiLooser = holdingIdentityResolver.getByUsername("Bob"); final var hiLooser = holdingIdentityResolver.getByUsername(player2);
final GameState game = cordaClient.gameProposalCreate( final GameState game = cordaClient.gameProposalCreate(
hiWinner, hiLooser, Stone.Color.WHITE, "GameBoard GLOBAL_RANKING test"); hiWinner, hiLooser, Stone.Color.WHITE, "GameBoard GLOBAL_RANKING test");
@ -45,7 +48,7 @@ public class RankingTests {
@Test @Test
void testIndividualRanking() { void testIndividualRanking() {
final var hiCustodian = holdingIdentityResolver.getByUsername("Bob"); final var hiCustodian = holdingIdentityResolver.getByUsername(player2);
final List<Rank> liderboard = cordaClient.fetchRanking(hiCustodian); final List<Rank> liderboard = cordaClient.fetchRanking(hiCustodian);
System.out.println(liderboard); System.out.println(liderboard);
} }

View File

@ -4,20 +4,20 @@
"cpi" : "CordaCheckers" "cpi" : "CordaCheckers"
}, },
{ {
"x500Name" : "CN=Bob, OU=Player, O=Checkers, L=Kyiv, C=UA", "x500Name" : "CN=Bobik, OU=Player, O=Checkers, L=Kyiv, C=UA",
"cpi" : "CordaCheckers" "cpi" : "CordaCheckers"
}, },
{ {
"x500Name" : "CN=Charlie, OU=Player, O=Checkers, L=London, C=GB", "x500Name" : "CN=Kumar, OU=Player, O=Checkers, L=Mumbai, C=IN",
"cpi" : "CordaCheckers" "cpi" : "CordaCheckers"
}, },
{ {
"x500Name" : "CN=Kumar, OU=Custodian, O=Checkers, L=Mumbai, C=IN", "x500Name" : "CN=Eva, OU=Custodian, O=Checkers, L=Rotkreuz, C=CH",
"cpi" : "CordaCheckers" "cpi" : "CordaCheckers"
}, },
{ {
"x500Name" : "CN=NotaryRep1, OU=Test Dept, O=R3, L=London, C=GB", "x500Name" : "CN=NotaryRep1, OU=Notary, O=Checkers, L=Rotkreuz, C=CH",
"cpi" : "NotaryServer", "cpi" : "NotaryServer",
"serviceX500Name": "CN=NotaryService, OU=Test Dept, O=R3, L=London, C=GB" "serviceX500Name" : "CN=Djmil, OU=Notary, O=Checkers, L=Rotkreuz, C=CH"
} }
] ]

View File

@ -0,0 +1,29 @@
package djmil.cordacheckers;
import net.corda.v5.application.flows.CordaInject;
import net.corda.v5.application.membership.MemberLookup;
import net.corda.v5.base.types.MemberX500Name;
import net.corda.v5.membership.MemberInfo;
import net.corda.v5.membership.NotaryInfo;
public class VNode {
static final String CHECKERS = "Checkers"; // O aka Organization
static final String CUSTODIAN = "Custodian"; // OU aka OrganizationUnit
static final String NOTARY = "Notary"; // OU aka OrganizationUnit
@CordaInject
MemberLookup memberLookup;
public static boolean isCordaCherckersCustodian(MemberInfo memberInfo) {
final MemberX500Name memberName = memberInfo.getName();
return memberName.getOrganization().equals(CHECKERS) &&
memberName.getOrganizationUnit().equals(CUSTODIAN);
}
public static boolean isCordaCherckersNotary(NotaryInfo notaryInfo) {
final MemberX500Name memberName = notaryInfo.getName();
return memberName.getOrganization().equals(CHECKERS) &&
memberName.getOrganizationUnit().equals(NOTARY);
}
}

View File

@ -10,6 +10,7 @@ import java.util.UUID;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import djmil.cordacheckers.VNode;
import djmil.cordacheckers.checkers.Stone; import djmil.cordacheckers.checkers.Stone;
import djmil.cordacheckers.contracts.GameCommand; import djmil.cordacheckers.contracts.GameCommand;
import djmil.cordacheckers.gamestate.CommitTrx; import djmil.cordacheckers.gamestate.CommitTrx;
@ -30,6 +31,7 @@ import net.corda.v5.ledger.common.NotaryLookup;
import net.corda.v5.ledger.utxo.UtxoLedgerService; import net.corda.v5.ledger.utxo.UtxoLedgerService;
import net.corda.v5.ledger.utxo.transaction.UtxoSignedTransaction; import net.corda.v5.ledger.utxo.transaction.UtxoSignedTransaction;
import net.corda.v5.membership.MemberInfo; import net.corda.v5.membership.MemberInfo;
import net.corda.v5.membership.NotaryInfo;
public class CreateFlow implements ClientStartableFlow{ public class CreateFlow implements ClientStartableFlow{
@ -42,7 +44,7 @@ public class CreateFlow implements ClientStartableFlow{
public MemberLookup memberLookup; public MemberLookup memberLookup;
@CordaInject @CordaInject
public NotaryLookup notaryLookup; NotaryLookup notaryLookup;
@CordaInject @CordaInject
public UtxoLedgerService utxoLedgerService; public UtxoLedgerService utxoLedgerService;
@ -64,7 +66,7 @@ public class CreateFlow implements ClientStartableFlow{
.addCommand(command) .addCommand(command)
.addOutputState(gameProposal) .addOutputState(gameProposal)
.addSignatories(gameProposal.getParticipants()) .addSignatories(gameProposal.getParticipants())
.setNotary(notaryLookup.getNotaryServices().iterator().next().getName()) .setNotary(findNotary().getName())
.setTimeWindowUntil(Instant.now().plusMillis(Duration.ofDays(1).toMillis())) .setTimeWindowUntil(Instant.now().plusMillis(Duration.ofDays(1).toMillis()))
.toSignedTransaction(); .toSignedTransaction();
@ -85,7 +87,7 @@ public class CreateFlow implements ClientStartableFlow{
} }
@Suspendable @Suspendable
private GameProposalState buildGameProposalStateFrom(ClientRequestBody requestBody) { GameProposalState buildGameProposalStateFrom(ClientRequestBody requestBody) {
final CreateFlowArgs args = requestBody.getRequestBodyAs(jsonMarshallingService, CreateFlowArgs.class); final CreateFlowArgs args = requestBody.getRequestBodyAs(jsonMarshallingService, CreateFlowArgs.class);
final Stone.Color opponentColor = Stone.Color.valueOf(args.opponentColor); final Stone.Color opponentColor = Stone.Color.valueOf(args.opponentColor);
@ -114,4 +116,13 @@ public class CreateFlow implements ClientStartableFlow{
); );
} }
@Suspendable
public NotaryInfo findNotary() {
return notaryLookup.getNotaryServices()
.stream()
.filter(notary -> VNode.isCordaCherckersNotary(notary))
.reduce((a,b) -> {throw new IllegalStateException("Multiple Notary VNodes");})
.orElseThrow( () -> new IllegalStateException("No Notary VNode found"));
}
} }

View File

@ -5,6 +5,7 @@ import java.time.Duration;
import java.time.Instant; import java.time.Instant;
import java.util.UUID; import java.util.UUID;
import djmil.cordacheckers.VNode;
import djmil.cordacheckers.contracts.GameCommand; import djmil.cordacheckers.contracts.GameCommand;
import djmil.cordacheckers.gamestate.CommitTrx; import djmil.cordacheckers.gamestate.CommitTrx;
import djmil.cordacheckers.gamestate.GetFlow; import djmil.cordacheckers.gamestate.GetFlow;
@ -72,7 +73,7 @@ public class GameResultCommiter implements SubFlow<SecureHash> {
MemberInfo findCustodian() { MemberInfo findCustodian() {
return memberLookup.lookup() return memberLookup.lookup()
.stream() .stream()
.filter(m -> m.getName().getOrganizationUnit().equals("Custodian") ) .filter(member -> VNode.isCordaCherckersCustodian(member) )
.reduce((a,b) -> {throw new IllegalStateException("Multiple Custodian VNodes");}) .reduce((a,b) -> {throw new IllegalStateException("Multiple Custodian VNodes");})
.orElseThrow( () -> new IllegalStateException("No Custodian VNode found")); .orElseThrow( () -> new IllegalStateException("No Custodian VNode found"));
} }