gpt4 book ai didi

node.js - 无法在截止日期前连接 URL :grpcs://localhost:8051

转载 作者:太空宇宙 更新时间:2023-11-03 23:50:10 26 4
gpt4 key购买 nike

我正在使用 docker-compose 运行 byfn 教程的修改版本,其中包含 5 个排序者、1 个组织、2 个对等点和 1 个 ca 服务。在本地,我正在 macOs Catalina 上使用 node v10.18.1 运行 Node 应用程序。hyperledger Fabric 版本 1.4 也正在使用中。

我尝试将与 grpcUrl 相关的 connection.json 文件中的路径从 localhost 替换为 dockerspect 命令提供的容器的 IP,也替换为 0.0.0.0,但没有成功,还使用 ​​telnet 来 grep 暴露的端口,并运行 docker ps 来检查所有容器是否都在使用正确的端口运行。

在我的代码中,我可以成功注册管理员和其他用户,但当我尝试连接到网关以调用链代码时失败。

我不断在 API 日志中收到错误:

2020-01-15T15:42:37.920Z - error: [Remote.js]: Error: Failed to connect before the deadline URL:grpcs://localhost:7051
2020-01-15T15:42:37.922Z - error: [Channel.js]: Error: Failed to connect before the deadline URL:grpcs://localhost:7051
2020-01-15T15:42:40.929Z - error: [Remote.js]: Error: Failed to connect before the deadline URL:grpcs://localhost:8051
2020-01-15T15:42:40.929Z - error: [Channel.js]: Error: Failed to connect before the deadline URL:grpcs://localhost:8051
2020-01-15T15:42:40.930Z - error: [Network]: _initializeInternalChannel: Unable to initialize channel. Attempted to contact 2 Peers. Last error was Error: Failed to connect before the deadline URL:grpcs://localhost:8051
level:warn time:2020-01-15T15:42:40.932Z message: "x-request-id_ac5294fd-9587-4432-87d9-ada4e73a1142 creating user product Unable to initialize channel. Attempted to contact 2 Peers. Last error was Error: Failed to connect before the deadline URL:grpcs://localhost:8051"

为什么我会收到此错误?

我的connection.json文件是:

{
"name": "first-network-org1",
"version": "1.0.0",
"client": {
"organization": "Org1",
"connection": {
"timeout": {
"peer": {
"endorser": "300"
}
}
}
},
"organizations": {
"Org1": {
"mspid": "Org1MSP",
"peers": [
"peer0.org1.example.com",
"peer1.org1.example.com"
],
"certificateAuthorities": [
"ca.org1.example.com"
]
}
},
"peers": {
"peer0.org1.example.com": {
"url": "grpcs://localhost:7051",
"tlsCACerts": {
"pem": "-----BEGIN CERTIFICATE-----...\n-----END CERTIFICATE-----\n"
},
"grpcOptions": {
"ssl-target-name-override": "peer0.org1.example.com",
"hostnameOverride": "peer0.org1.example.com"
}
},
"peer1.org1.example.com": {
"url": "grpcs://localhost:8051",
"tlsCACerts": {
"pem": "-----BEGIN CERTIFICATE-----...\n-----END CERTIFICATE-----\n"
},
"grpcOptions": {
"ssl-target-name-override": "peer1.org1.example.com",
"hostnameOverride": "peer1.org1.example.com"
}
}
},
"certificateAuthorities": {
"ca.org1.example.com": {
"url": "https://localhost:7054",
"caName": "ca-org1",
"tlsCACerts": {
"pem": "-----BEGIN CERTIFICATE-----...\n-----END CERTIFICATE-----\n"
},
"httpOptions": {
"verify": false
}
}
}
}

这些是我的 package.json 文件中的依赖项(请记住,我已尝试手动安装最新的 grpc 模块,但没有成功):

"dependencies": {
"body-parser": "^1.18.3",
"cors": "^2.8.5",
"express": "^4.16.4",
"fabric-ca-client": "^1.4.4",
"fabric-client": "^1.4.4",
"fabric-network": "^1.4.4",
"helmet": "^3.15.1",
"http-status": "^1.3.1",
"joi": "^14.3.1",
"lodash": "^4.17.11",
"nconf": "^0.10.0",
"request-promise": "^4.2.4",
"swagger-stats": "^0.95.7",
"uuid": "^3.3.2",
"winston": "^3.2.1",
"xss": "^1.0.3"
}

这是我的失败代码:

const initGateway = async (params) => {
try {
const {
wallet,
identity,
discovery, // object with { enabled: true, asLocalhost: true }
channelName,
contractName
} = params;

// Create a new gateway for connecting to our peer node.
const gateway = new Gateway();
await gateway.connect(ccpPath, { wallet, identity, discovery });

// Get the network (channel) our contract is deployed to.
const network = await gateway.getNetwork(channelName);
logger.info({ message: `NETWORK ${network}` });
// Get the contract from the network.
const contract = network.getContract(contractName);

return { gateway, contract };
} catch (err) {
throw err;
}
};

const createProduct = async (dataObj) => {
try {
const {
userIdentity,
seller,
value,
description,
issueDateTime,
productId
} = dataObj;
// Create a new file system based wallet for managing identities
const wallet = new FileSystemWallet(walletFilePath);

const params = {
wallet,
identity: userIdentity,
discovery: { enabled: true, asLocalhost: true },
channelName: 'mychannel',
contractName: 'mychaincode'
};
// Get the contract from the network.
const { gateway, contract } = await initGateway(params);

await contract.submitTransaction('setForSale', seller, productId, issueDateTime, value, description);

// Disconnect from the gateway.
await gateway.disconnect();
} catch (err) {
throw err;
}
};

最佳答案

通过在 docker-compose 文件中查找 CORE_PEER_TLS_ENABLED=true 标志,确保为对等点启用 TLS 通信。如果未设置为 true,则将连接配置文件中的对等 URL 从 grpcs://localhost:7051 修改为 grpc://localhost:7051

关于node.js - 无法在截止日期前连接 URL :grpcs://localhost:8051,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59755418/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com