Browse Source

modify method of get topology from bft-smart server

tags/1.1.11
shaozhuguang 5 years ago
parent
commit
26c05ec214
5 changed files with 11 additions and 24 deletions
  1. +7
    -9
      source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartConsensusManageService.java
  2. +3
    -0
      source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartNodeServer.java
  3. +1
    -1
      source/gateway/src/main/java/com/jd/blockchain/gateway/service/PeerConnectionManager.java
  4. +0
    -5
      source/peer/src/main/java/com/jd/blockchain/peer/web/ManagementController.java
  5. +0
    -9
      source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/service/PeerBlockchainServiceFactory.java

+ 7
- 9
source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartConsensusManageService.java View File

@@ -40,23 +40,21 @@ public class BftsmartConsensusManageService implements ConsensusManageService {
@Override @Override
public BftsmartClientIncomingSettings authClientIncoming(ClientIdentification authId) { public BftsmartClientIncomingSettings authClientIncoming(ClientIdentification authId) {
if (verify(authId)) { if (verify(authId)) {
byte[] topology = BinarySerializeUtils.serialize(nodeServer.getTopology());
byte[] tomConfig = BinarySerializeUtils.serialize(nodeServer.getTomConfig());
BftsmartTopology topology = nodeServer.getTopology();
if (topology == null) {
throw new IllegalStateException("Topology still not created !!!");
}


LOGGER.info("topology:{}, tomConfig:{}", topology == null ? 0 : topology.length,
tomConfig == null ? 0: tomConfig.length);
byte[] topologyBytes = BinarySerializeUtils.serialize(topology);
LOGGER.info("Topology = {}", topologyBytes == null ? 0 : topologyBytes.length);


BftsmartClientIncomingConfig clientIncomingSettings = new BftsmartClientIncomingConfig(); BftsmartClientIncomingConfig clientIncomingSettings = new BftsmartClientIncomingConfig();

clientIncomingSettings clientIncomingSettings
.setTopology(BinarySerializeUtils.serialize(nodeServer.getTopology()));

.setTopology(BinarySerializeUtils.serialize(topology));
clientIncomingSettings clientIncomingSettings
.setTomConfig(BinarySerializeUtils.serialize(nodeServer.getTomConfig())); .setTomConfig(BinarySerializeUtils.serialize(nodeServer.getTomConfig()));

clientIncomingSettings clientIncomingSettings
.setConsensusSettings(nodeServer.getConsensusSetting()); .setConsensusSettings(nodeServer.getConsensusSetting());

clientIncomingSettings.setPubKey(authId.getPubKey()); clientIncomingSettings.setPubKey(authId.getPubKey());
// compute gateway id // compute gateway id
authLock.lock(); authLock.lock();


+ 3
- 0
source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartNodeServer.java View File

@@ -194,6 +194,9 @@ public class BftsmartNodeServer extends DefaultRecoverable implements NodeServer
} }


public BftsmartTopology getTopology() { public BftsmartTopology getTopology() {
if (!isRunning()) {
return null;
}
if (outerTopology != null) { if (outerTopology != null) {
return outerTopology; return outerTopology;
} }


+ 1
- 1
source/gateway/src/main/java/com/jd/blockchain/gateway/service/PeerConnectionManager.java View File

@@ -145,7 +145,7 @@ public class PeerConnectionManager implements PeerService, PeerConnector {
LOGGER.error("Peer connect fail {}", peerAddress); LOGGER.error("Peer connect fail {}", peerAddress);
} }
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("Peer connect fail {}", peerAddress);
LOGGER.error(String.format("Peer connect fail %s", peerAddress), e);
} }
} }
} }


+ 0
- 5
source/peer/src/main/java/com/jd/blockchain/peer/web/ManagementController.java View File

@@ -159,13 +159,9 @@ public class ManagementController implements LedgerBindingConfigAware, PeerManag
List<LedgerIncomingSetting> ledgerIncomingList = new ArrayList<LedgerIncomingSetting>(); List<LedgerIncomingSetting> ledgerIncomingList = new ArrayList<LedgerIncomingSetting>();


for (HashDigest ledgerHash : ledgerPeers.keySet()) { for (HashDigest ledgerHash : ledgerPeers.keySet()) {

NodeServer peer = ledgerPeers.get(ledgerHash); NodeServer peer = ledgerPeers.get(ledgerHash);

String peerProviderName = peer.getProviderName(); String peerProviderName = peer.getProviderName();

ConsensusProvider provider = ConsensusProviders.getProvider(peer.getProviderName()); ConsensusProvider provider = ConsensusProviders.getProvider(peer.getProviderName());

ClientIncomingSettings clientIncomingSettings = null; ClientIncomingSettings clientIncomingSettings = null;
for (ClientIdentification authId : identificationArray) { for (ClientIdentification authId : identificationArray) {
if (authId.getProviderName() == null || if (authId.getProviderName() == null ||
@@ -188,7 +184,6 @@ public class ManagementController implements LedgerBindingConfigAware, PeerManag
byte[] clientIncomingBytes = provider.getSettingsFactory().getIncomingSettingsEncoder() byte[] clientIncomingBytes = provider.getSettingsFactory().getIncomingSettingsEncoder()
.encode(clientIncomingSettings); .encode(clientIncomingSettings);
String base64ClientIncomingSettings = ByteArray.toBase64(clientIncomingBytes); String base64ClientIncomingSettings = ByteArray.toBase64(clientIncomingBytes);

LedgerIncomingSetting ledgerIncomingSetting = new LedgerIncomingSetting(); LedgerIncomingSetting ledgerIncomingSetting = new LedgerIncomingSetting();
ledgerIncomingSetting.setLedgerHash(ledgerHash); ledgerIncomingSetting.setLedgerHash(ledgerHash);
ledgerIncomingSetting.setCryptoSetting(ledgerCryptoSettings.get(ledgerHash)); ledgerIncomingSetting.setCryptoSetting(ledgerCryptoSettings.get(ledgerHash));


+ 0
- 9
source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/service/PeerBlockchainServiceFactory.java View File

@@ -91,22 +91,17 @@ public class PeerBlockchainServiceFactory implements BlockchainServiceFactory, C
* @return 区块链服务工厂实例; * @return 区块链服务工厂实例;
*/ */
public synchronized static PeerBlockchainServiceFactory connect(AsymmetricKeypair gatewayKey, NetworkAddress peerAddr, List<String> peerProviders) { public synchronized static PeerBlockchainServiceFactory connect(AsymmetricKeypair gatewayKey, NetworkAddress peerAddr, List<String> peerProviders) {

if (peerProviders == null || peerProviders.isEmpty()) { if (peerProviders == null || peerProviders.isEmpty()) {
throw new AuthenticationException("No peer Provider was set!"); throw new AuthenticationException("No peer Provider was set!");
} }
ClientIdentificationsProvider authIdProvider = authIdProvider(gatewayKey, peerProviders); ClientIdentificationsProvider authIdProvider = authIdProvider(gatewayKey, peerProviders);

GatewayIncomingSetting incomingSetting = auth(peerAddr, authIdProvider); GatewayIncomingSetting incomingSetting = auth(peerAddr, authIdProvider);

if (incomingSetting == null) { if (incomingSetting == null) {
throw new AuthenticationException("No peer was succeed authenticating from!"); throw new AuthenticationException("No peer was succeed authenticating from!");
} }


PeerBlockchainServiceFactory factory = null; PeerBlockchainServiceFactory factory = null;

ServiceConnectionManager httpConnectionManager; ServiceConnectionManager httpConnectionManager;

PeerManageService peerManageService; PeerManageService peerManageService;


if (peerBlockchainServiceFactories.containsKey(peerAddr)) { if (peerBlockchainServiceFactories.containsKey(peerAddr)) {
@@ -164,16 +159,13 @@ public class PeerBlockchainServiceFactory implements BlockchainServiceFactory, C


TransactionService autoSigningTxProcService = enableGatewayAutoSigning(gatewayKey, TransactionService autoSigningTxProcService = enableGatewayAutoSigning(gatewayKey,
ledgerSetting.getCryptoSetting(), consensusClient); ledgerSetting.getCryptoSetting(), consensusClient);

LedgerAccessContextImpl accCtx = new LedgerAccessContextImpl(); LedgerAccessContextImpl accCtx = new LedgerAccessContextImpl();
accCtx.ledgerHash = ledgerSetting.getLedgerHash(); accCtx.ledgerHash = ledgerSetting.getLedgerHash();
accCtx.cryptoSetting = ledgerSetting.getCryptoSetting(); accCtx.cryptoSetting = ledgerSetting.getCryptoSetting();
accCtx.queryService = queryService; accCtx.queryService = queryService;
accCtx.txProcService = autoSigningTxProcService; accCtx.txProcService = autoSigningTxProcService;
accCtx.consensusClient = consensusClient; accCtx.consensusClient = consensusClient;

accessAbleLedgers[i] = accCtx; accessAbleLedgers[i] = accCtx;

tempAccessCtxs.put(accCtx.ledgerHash, accCtx); tempAccessCtxs.put(accCtx.ledgerHash, accCtx);
// 添加对应Hash到该Peer节点 // 添加对应Hash到该Peer节点
currentPeerLedgers.add(accCtx.ledgerHash); currentPeerLedgers.add(accCtx.ledgerHash);
@@ -189,7 +181,6 @@ public class PeerBlockchainServiceFactory implements BlockchainServiceFactory, C
LOGGER.info("First connect, peer[{}] init new ledger[{}] OK !!!", peerAddr, hash.toBase58()); LOGGER.info("First connect, peer[{}] init new ledger[{}] OK !!!", peerAddr, hash.toBase58());
} }
} }

} else { } else {
factory.accessContextMap.putAll(tempAccessCtxs); factory.accessContextMap.putAll(tempAccessCtxs);
factory.addLedgerAccessContexts(accessAbleLedgers); factory.addLedgerAccessContexts(accessAbleLedgers);


Loading…
Cancel
Save