Skip to content

Commit

Permalink
debug: add logs
Browse files Browse the repository at this point in the history
  • Loading branch information
0xpatrickdev committed Mar 25, 2024
1 parent 2d01f67 commit 6d2d41b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 9 deletions.
34 changes: 30 additions & 4 deletions packages/network/src/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ const prepareInboundAttempt = (zone, makeConnection, { watch }) => {
* @param {import('@agoric/network/src/types.js').ConnectionHandler} opts.handler
*/
async accept({ localAddress, remoteAddress, handler: rchandler }) {
console.log('@@@accept', localAddress, remoteAddress);
const { consummated, localAddr, remoteAddr } = this.state;
const { listening, listenPrefix, currentConnections } = this.state;
if (consummated) {
Expand All @@ -492,6 +493,8 @@ const prepareInboundAttempt = (zone, makeConnection, { watch }) => {

const [port, listener] = listening.get(listenPrefix);
const current = currentConnections.get(port);
console.log('@@@accept::port', port);
console.log('@@@accept::port', listenPrefix);

current.delete(this.facets.inboundAttempt);

Expand All @@ -511,7 +514,11 @@ const prepareInboundAttempt = (zone, makeConnection, { watch }) => {
onFulfilled(lchandler, watchContext) {
const { localAddress, rchandler, remoteAddress, current } =
watchContext;

console.log(
'@@@inboundAttemptAcceptWatcher::onFulfilled',
localAddress,
remoteAddress,
);
return crossoverConnection(
zone,
lchandler,
Expand Down Expand Up @@ -615,11 +622,13 @@ const preparePort = (zone, powers) => {
},
/** @param {ListenHandler} listenHandler */
async addListener(listenHandler) {
console.log('@@@port:addListener fired');
const { revoked, listening, localAddr, protocolHandler } = this.state;

!revoked || Fail`Port ${this.state.localAddr} is revoked`;
listenHandler || Fail`listenHandler is not defined`;

console.log('@@@port:addListener', localAddr);
if (listening.has(localAddr)) {
// Last one wins.
const [lport, lhandler] = listening.get(localAddr);
Expand Down Expand Up @@ -919,7 +928,7 @@ const prepareBinder = (zone, powers) => {
const prefixes = getPrefixes(listenAddr);
let listenPrefixIndex = 0;
let listenPrefix;

console.log('@@@inbound:prefixes', prefixes);
while (listenPrefixIndex < prefixes.length) {
listenPrefix = prefixes[listenPrefixIndex];
if (!listening.has(listenPrefix)) {
Expand All @@ -929,8 +938,10 @@ const prepareBinder = (zone, powers) => {

break;
}

console.log('@@@inbound:listenPrefixIndex', listenPrefixIndex);
console.log('@@@inbound:listenPrefix', listenPrefix);
if (listenPrefixIndex >= prefixes.length) {
// XXX this throws
throw Error(`No listeners for ${listenAddr}`);
}

Expand Down Expand Up @@ -972,7 +983,7 @@ const prepareBinder = (zone, powers) => {
const { protocolHandler } = this.state;

const localAddr = await E(port).getLocalAddress();

console.log('@@@outbound:localAddr', localAddr);
// Allocate a local address.
const instantiateInnerVow = watch(
E(protocolHandler).onInstantiate(
Expand Down Expand Up @@ -1161,6 +1172,7 @@ const prepareBinder = (zone, powers) => {
},
binderOutboundCatchWatcher: {
onRejected(e, watchContext) {
console.log('@@@binderOutboundCatchWatcher');
let lastFailure;

try {
Expand Down Expand Up @@ -1200,6 +1212,19 @@ const prepareBinder = (zone, powers) => {
initialLocalAddress = localAddr;
}

console.log(
'@@@binderOutboundInboundWatcher::initialLocalAddress',
initialLocalAddress,
);
console.log(
'@@@binderOutboundInboundWatcher::watchContext',
JSON.stringify(watchContext),
);
console.log(
'@@@binderOutboundInboundWatcher::remoteAddr',
remoteAddr,
);

// Attempt the loopback connection.
return this.facets.protocolImpl.inbound(
remoteAddr,
Expand All @@ -1209,6 +1234,7 @@ const prepareBinder = (zone, powers) => {
},
binderOutboundAcceptWatcher: {
onFulfilled(attempt, watchContext) {
console.log('@@@binderOutboundAcceptWatcher', attempt);
const { handler } = watchContext;
return attempt.accept({ handler });
},
Expand Down
9 changes: 9 additions & 0 deletions packages/network/src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,16 @@ export const prepareRouterProtocol = (zone, powers, E = defaultE) => {
* @param {ProtocolHandler} protocolHandler
*/
registerProtocolHandler(paths, protocolHandler) {
console.log(
'@@@registerProtocolHandler::args',
JSON.stringify(paths),
protocolHandler,
);
const protocol = makeNetworkProtocol(protocolHandler);
console.log(
'@@@registerProtocolHandler::makeNetworkProtocol',
protocol,
);
for (const prefix of paths) {
this.state.router.register(prefix, protocol);
this.state.protocols.init(prefix, protocol);
Expand Down
12 changes: 7 additions & 5 deletions packages/vats/src/proposals/network-proposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const registerNetworkProtocols = async (vats, dibcBridgeManager) => {
const loopbackHandler = await E(vats.network).makeLoopbackProtocolHandler();
// Every vat has a loopback device.
ps.push(E(vats.network).registerProtocolHandler(['/local'], loopbackHandler));

console.log('@@@dibcBridgeManager', dibcBridgeManager);
if (dibcBridgeManager) {
assert('ibc' in vats);
// We have access to the bridge, and therefore IBC.
Expand All @@ -33,15 +33,17 @@ export const registerNetworkProtocols = async (vats, dibcBridgeManager) => {
.then(({ protocolHandler, bridgeHandler }) =>
E(dibcBridgeManager)
.initHandler(bridgeHandler)
.then(() =>
E(vats.network).registerProtocolHandler(
.then(() => {
console.log('@@@initHandler');
return E(vats.network).registerProtocolHandler(
['/ibc-port', '/ibc-hop'],
protocolHandler,
),
),
);
}),
),
);
} else {
console.log('@@@dibcBridgeManager::else');
const loHandler = await E(vats.network).makeLoopbackProtocolHandler(
'ibc-channel/channel-',
);
Expand Down

0 comments on commit 6d2d41b

Please sign in to comment.