@@ -57,6 +57,7 @@ public class ImmuClient {
5757 private final ImmuStateHolder stateHolder ;
5858 private ManagedChannel channel ;
5959 private String authToken ;
60+ private String currentServerUuid ;
6061 private String currentDb = "defaultdb" ;
6162
6263 public ImmuClient (Builder builder ) {
@@ -72,10 +73,24 @@ public static Builder newBuilder() {
7273 private ImmuServiceGrpc .ImmuServiceBlockingStub createStubFrom (Builder builder ) {
7374 channel = ManagedChannelBuilder .forAddress (builder .getServerUrl (), builder .getServerPort ())
7475 .usePlaintext ()
76+ .intercept (new ImmuServerUUIDInterceptor (this ))
7577 .build ();
7678 return ImmuServiceGrpc .newBlockingStub (channel );
7779 }
7880
81+ // ---------------------------------------------------------------------
82+ // These two currentServerUuid related methods are not publicly exposed,
83+ // since these should be called by the ImmuServerUUIDInterceptor only.
84+
85+ void setCurrentServerUuid (String serverUuid ) {
86+ currentServerUuid = serverUuid ;
87+ }
88+
89+ String getCurrentServerUuid () {
90+ return currentServerUuid ;
91+ }
92+ // ---------------------------------------------------------------------
93+
7994 public synchronized void shutdown () {
8095 if (channel == null ) {
8196 return ;
@@ -99,7 +114,6 @@ private ImmuServiceGrpc.ImmuServiceBlockingStub getStub() {
99114 if (!withAuthToken || authToken == null ) {
100115 return stub ;
101116 }
102-
103117 Metadata metadata = new Metadata ();
104118 metadata .put (Metadata .Key .of (AUTH_HEADER , Metadata .ASCII_STRING_MARSHALLER ), "Bearer " + authToken );
105119
@@ -128,10 +142,10 @@ public synchronized void logout() {
128142 * If nothing exists already, it is fetched from the server and save it locally.
129143 */
130144 public ImmuState state () {
131- ImmuState state = stateHolder .getState (currentDb );
145+ ImmuState state = stateHolder .getState (currentServerUuid , currentDb );
132146 if (state == null ) {
133147 state = currentState ();
134- stateHolder .setState (state );
148+ stateHolder .setState (currentServerUuid , state );
135149 }
136150 return state ;
137151 }
@@ -336,7 +350,7 @@ private Entry verifiedGet(ImmudbProto.KeyRequest keyReq, ImmuState state) throws
336350 // TODO: to-be-implemented (see pkg/client/client.go:620, newState.CheckSignature(c.serverSigningPubKey))
337351 // if (serverSigningPubKey != null) { }
338352
339- stateHolder .setState (newState );
353+ stateHolder .setState (currentServerUuid , newState );
340354
341355 return Entry .valueOf (vEntry .getEntry ());
342356 }
@@ -527,7 +541,7 @@ public TxMetadata verifiedSet(byte[] key, byte[] value) throws VerificationExcep
527541 // TODO: to-be-implemented (see pkg/client/client.go:803 newState.CheckSignature ...)
528542 // if (serverSigningPubKey != null) { ... }
529543
530- stateHolder .setState (newState );
544+ stateHolder .setState (currentServerUuid , newState );
531545
532546 return TxMetadata .valueOf (vtx .getTx ().getMetadata ());
533547 }
@@ -579,7 +593,7 @@ public TxMetadata verifiedSetReferenceAt(byte[] key, byte[] referencedKey, long
579593 // TODO: to-be-implemented (see pkg/client/client.go:1122 newState.CheckSignature ...)
580594 // if (serverSigningPubKey != null) { ... }
581595
582- stateHolder .setState (newState );
596+ stateHolder .setState (currentServerUuid , newState );
583597
584598 return TxMetadata .valueOf (vtx .getTx ().getMetadata ());
585599 }
@@ -686,7 +700,7 @@ public TxMetadata verifiedZAddAt(byte[] set, double score, byte[] key, long atTx
686700 // TODO: to-be-implemented (see pkg/client/client.go:803 newState.CheckSignature ...)
687701 // if (serverSigningPubKey != null) { ... }
688702
689- stateHolder .setState (newState );
703+ stateHolder .setState (currentServerUuid , newState );
690704
691705 return TxMetadata .valueOf (vtx .getTx ().getMetadata ());
692706 }
@@ -769,7 +783,7 @@ public Tx verifiedTxById(long txId) throws VerificationException {
769783 // TODO: to-be-implemented (see pkg/client/client.go:803 newState.CheckSignature ...)
770784 // if (serverSigningPubKey != null) { ... }
771785
772- stateHolder .setState (newState );
786+ stateHolder .setState (currentServerUuid , newState );
773787
774788 Tx tx = null ;
775789 try {
0 commit comments