Closed NormandoHall closed 2 years ago
Hi Normando,
I think the problem is that Meta.addCallback
is expecting a direct proxy, a proxy with endpoints, and here your callback is a fixed proxy that doesn't include any endpoints.
Using Glacier2 can overcome this, the proxy pass to Meta.addCallback
will use the Glacier2 router server endpoints, and Glacier2 will route the callback to your JavaScript client throw the existing connection.
See https://doc.zeroc.com/ice/3.7/ice-services/glacier2/callbacks-through-glacier2
In your example you are using the implicit request context, in order to have Glacier2 forward the context you need to set Glacier2.Client.ForwardContext
and, or Glacier2.Server.ForwardContext
in you Glacier2 configuration. See the details in https://doc.zeroc.com/ice/3.7/property-reference/glacier2
You client code would be something like
const { Ice, Glacier2 } = require("ice");
const { Murmur } = require("./ice/Murmur.js");
let communicator = null
let proxy = null
class MetaCallbackI extends Murmur.MetaCallback
{
started()
{
console.log('Started');
}
stopped()
{
console.log('Stopped')
}
}
(async function _init() {
try{
const iceOptions = new Ice.InitializationData();
iceOptions.properties = Ice.createProperties([], iceOptions.properties);
iceOptions.properties.setProperty("Ice.Default.EncodingVersion", "1.0");
iceOptions.properties.setProperty("Ice.ImplicitContext", "Shared");
iceOptions.properties.setProperty("Ice.Default.Router", "DemoGlacier2/router:tcp -p 4063 -h localhost");
communicator = Ice.initialize(iceOptions);
communicator.getImplicitContext().put("secret", 'xxxx');
proxy = await Murmur.MetaPrx.checkedCast(communicator.stringToProxy("Meta:tcp -h 127.0.0.1 -p 6502")); // proxy
const router = await Glacier2.RouterPrx.checkedCast(communicator.getDefaultRouter());
const session = await router.createSession("user", "password");
const [timeout, category, adapter] = await Promise.all(
[
router.getACMTimeout(),
router.getCategoryForClient(),
router.ice_getCommunicator().createObjectAdapterWithRouter("", router)
]);
const connection = router.ice_getCachedConnection();
if(timeout > 0)
{
connection.setACM(timeout, undefined, Ice.ACMHeartbeat.HeartbeatAlways);
}
connection.setCloseCallback(() => error("Connection lost"));
const receiver = Murmur.MetaCallbackPrx.uncheckedCast(
adapter.add(new MetaCallbackI(), new Ice.Identity("callback", category)));
await proxy.addCallback(receiver);
await communicator.waitForShutdown();
}catch (ex){
return {err: ex.toString()};
}
})()
Note I didn't test the code I just adapted yours based on our demo https://github.com/zeroc-ice/ice-demos/tree/3.7/js/Glacier2/simpleChat
@pepone thank you for your help.
I tried your code and get errors. The error is:
::Ice::ConnectionLostException
error: "0"
and comes from this line:
proxy = await Murmur.MetaPrx.checkedCast(communicator.stringToProxy("Meta:tcp -h 127.0.0.1 -p 6502")); // proxy
I was moved down this line after connection.setCloseCallback(() => error("Connection lost"));
with same results.
I suppose the proxy should be called from the router.
Thanks
Hi Normando,
I suppose the proxy should be called from the router.
Yes, that is correct.
Can you enable network and protocol tracing by setting:
iceOptions.properties.setProperty("Ice.Trace.Network", "3");
iceOptions.properties.setProperty("Ice.Trace.Protocol", "1");
You should enable this in glacier2router, and the server. Maybe the logs give us a clue what is wrong here.
Hi Jose. I executed the code in local server, and in remote server, with the same results.
-- 2/6/2022, 17:26:48.839 Network: trying to establish tcp connection to 192.168.10.20:50055
-- 2/6/2022, 17:26:48.874 Network: received 14 of 14 bytes via tcp
local address = 192.168.10.10:52364
remote address = 192.168.10.20:50055
-- 2/6/2022, 17:26:48.875 Protocol: received validate connection
message type = 3 (validate connection)
compression status = 0 (not compressed; do not compress response, if any)
message size = 14
-- 2/6/2022, 17:26:48.876 Network: established tcp connection
local address = 192.168.10.10:52364
remote address = 192.168.10.20:50055
-- 2/6/2022, 17:26:48.879 Protocol: sending request
message type = 0 (request)
compression status = 0 (not compressed; do not compress response, if any)
message size = 91
request id = 1
identity = DemoGlacier2/router
facet =
operation = ice_isA
mode = 1 (nonmutating)
context = secret/xxxx
-- 2/6/2022, 17:26:48.880 Network: sent 91 of 91 bytes via tcp
local address = 192.168.10.10:52364
remote address = 192.168.10.20:50055
-- 2/6/2022, 17:26:48.884 Network: closed tcp connection
local address = 192.168.10.10:52364
remote address = 192.168.10.20:50055
::Ice::ConnectionLostException
error: "0"
-- 2/6/2022, 17:26:48.887 Network: trying to establish tcp connection to 192.168.10.20:50055
-- 2/6/2022, 17:26:48.889 Network: received 14 of 14 bytes via tcp
local address = 192.168.10.10:52366
remote address = 192.168.10.20:50055
-- 2/6/2022, 17:26:48.890 Protocol: received validate connection
message type = 3 (validate connection)
compression status = 0 (not compressed; do not compress response, if any)
message size = 14
-- 2/6/2022, 17:26:48.890 Network: established tcp connection
local address = 192.168.10.10:52366
remote address = 192.168.10.20:50055
-- 2/6/2022, 17:26:48.891 Protocol: sending request
message type = 0 (request)
compression status = 0 (not compressed; do not compress response, if any)
message size = 91
request id = 1
identity = DemoGlacier2/router
facet =
operation = ice_isA
mode = 1 (nonmutating)
context = secret/xxxx
-- 2/6/2022, 17:26:48.892 Network: sent 91 of 91 bytes via tcp
local address = 192.168.10.10:52366
remote address = 192.168.10.20:50055
-- 2/6/2022, 17:26:48.893 Network: closed tcp connection
local address = 192.168.10.10:52366
remote address = 192.168.10.20:50055
::Ice::ConnectionLostException
error: "0"
::Ice::ConnectionLostException
error: "0"
-- 2/6/2022, 17:29:56.1 Network: trying to establish tcp connection to localhost:4063
-- 2/6/2022, 17:29:56.114 Network: received 14 of 14 bytes via tcp
local address = 127.0.0.1:60684
remote address = 127.0.0.1:4063
-- 2/6/2022, 17:29:56.115 Protocol: received validate connection
message type = 3 (validate connection)
compression status = 0 (not compressed; do not compress response, if any)
message size = 14
-- 2/6/2022, 17:29:56.116 Network: established tcp connection
local address = 127.0.0.1:60684
remote address = 127.0.0.1:4063
-- 2/6/2022, 17:29:56.118 Protocol: sending request
message type = 0 (request)
compression status = 0 (not compressed; do not compress response, if any)
message size = 91
request id = 1
identity = DemoGlacier2/router
facet =
operation = ice_isA
mode = 1 (nonmutating)
context = secret/xxxx
-- 2/6/2022, 17:29:56.119 Network: sent 91 of 91 bytes via tcp
local address = 127.0.0.1:60684
remote address = 127.0.0.1:4063
-- 2/6/2022, 17:29:56.123 Network: closed tcp connection
local address = 127.0.0.1:60684
remote address = 127.0.0.1:4063
::Ice::ConnectionLostException
error: "0"
-- 2/6/2022, 17:29:56.125 Network: trying to establish tcp connection to localhost:4063
-- 2/6/2022, 17:29:56.127 Network: received 14 of 14 bytes via tcp
local address = 127.0.0.1:60686
remote address = 127.0.0.1:4063
-- 2/6/2022, 17:29:56.127 Protocol: received validate connection
message type = 3 (validate connection)
compression status = 0 (not compressed; do not compress response, if any)
message size = 14
-- 2/6/2022, 17:29:56.128 Network: established tcp connection
local address = 127.0.0.1:60686
remote address = 127.0.0.1:4063
-- 2/6/2022, 17:29:56.128 Protocol: sending request
message type = 0 (request)
compression status = 0 (not compressed; do not compress response, if any)
message size = 91
request id = 1
identity = DemoGlacier2/router
facet =
operation = ice_isA
mode = 1 (nonmutating)
context = secret/xxxx
-- 2/6/2022, 17:29:56.129 Network: sent 91 of 91 bytes via tcp
local address = 127.0.0.1:60686
remote address = 127.0.0.1:4063
-- 2/6/2022, 17:29:56.130 Network: closed tcp connection
local address = 127.0.0.1:60686
remote address = 127.0.0.1:4063
::Ice::ConnectionLostException
error: "0"
::Ice::ConnectionLostException
error: "0"
Hi Normando,
Can you post the trancing for the glacier2router process?
Catched!
iceOptions.properties.setProperty("Ice.Default.Router", "DemoGlacier2/router:tcp -p 4063 -h localhost");
should be
iceOptions.properties.setProperty("Ice.Default.Router", "Glacier2/router:tcp -p 4063 -h localhost");
Now I will try to get the callback running. I will get back Jose, sorry to bother you.
This is the output now:
-- 2/6/2022, 18:00:14.21 Network: trying to establish tcp connection to 192.168.10.20:50055
-- 2/6/2022, 18:00:14.89 Network: received 14 of 14 bytes via tcp
local address = 192.168.10.10:57926
remote address = 192.168.10.20:50055
-- 2/6/2022, 18:00:14.91 Protocol: received validate connection
message type = 3 (validate connection)
compression status = 0 (not compressed; do not compress response, if any)
message size = 14
-- 2/6/2022, 18:00:14.92 Network: established tcp connection
local address = 192.168.10.10:57926
remote address = 192.168.10.20:50055
-- 2/6/2022, 18:00:14.98 Protocol: sending request
message type = 0 (request)
compression status = 0 (not compressed; do not compress response, if any)
message size = 87
request id = 1
identity = Glacier2/router
facet =
operation = ice_isA
mode = 1 (nonmutating)
context = secret/xxxx
-- 2/6/2022, 18:00:14.100 Network: sent 87 of 87 bytes via tcp
local address = 192.168.10.10:57926
remote address = 192.168.10.20:50055
-- 2/6/2022, 18:00:14.101 Network: received 14 of 14 bytes via tcp
local address = 192.168.10.10:57926
remote address = 192.168.10.20:50055
-- 2/6/2022, 18:00:14.102 Network: received 12 of 12 bytes via tcp
local address = 192.168.10.10:57926
remote address = 192.168.10.20:50055
-- 2/6/2022, 18:00:14.103 Protocol: received reply
message type = 2 (reply)
compression status = 0 (not compressed; do not compress response, if any)
message size = 26
request id = 1
reply status = 0 (ok)
-- 2/6/2022, 18:00:14.106 Protocol: sending request
message type = 0 (request)
compression status = 0 (not compressed; do not compress response, if any)
message size = 85
request id = 2
identity = Glacier2/router
facet =
operation = createSession
mode = 0 (normal)
context = secret/xxxx
-- 2/6/2022, 18:00:14.107 Network: sent 85 of 85 bytes via tcp
local address = 192.168.10.10:57926
remote address = 192.168.10.20:50055
-- 2/6/2022, 18:00:14.108 Network: received 14 of 14 bytes via tcp
local address = 192.168.10.10:57926
remote address = 192.168.10.20:50055
-- 2/6/2022, 18:00:14.109 Network: received 13 of 13 bytes via tcp
local address = 192.168.10.10:57926
remote address = 192.168.10.20:50055
-- 2/6/2022, 18:00:14.110 Protocol: received reply
message type = 2 (reply)
compression status = 0 (not compressed; do not compress response, if any)
message size = 27
request id = 2
reply status = 0 (ok)
-- 2/6/2022, 18:00:14.111 Protocol: sending request
message type = 0 (request)
compression status = 0 (not compressed; do not compress response, if any)
message size = 74
request id = 3
identity = Glacier2/router
facet =
operation = getACMTimeout
mode = 1 (nonmutating)
context = secret/xxxx
-- 2/6/2022, 18:00:14.112 Network: sent 74 of 74 bytes via tcp
local address = 192.168.10.10:57926
remote address = 192.168.10.20:50055
-- 2/6/2022, 18:00:14.113 Protocol: sending request
message type = 0 (request)
compression status = 0 (not compressed; do not compress response, if any)
message size = 81
request id = 4
identity = Glacier2/router
facet =
operation = getCategoryForClient
mode = 1 (nonmutating)
context = secret/xxxx
-- 2/6/2022, 18:00:14.114 Network: sent 81 of 81 bytes via tcp
local address = 192.168.10.10:57926
remote address = 192.168.10.20:50055
-- 2/6/2022, 18:00:14.119 Protocol: sending request
message type = 0 (request)
compression status = 0 (not compressed; do not compress response, if any)
message size = 75
request id = 5
identity = Glacier2/router
facet =
operation = getClientProxy
mode = 1 (nonmutating)
context = secret/xxxx
-- 2/6/2022, 18:00:14.120 Network: sent 75 of 75 bytes via tcp
local address = 192.168.10.10:57926
remote address = 192.168.10.20:50055
-- 2/6/2022, 18:00:14.121 Network: received 14 of 14 bytes via tcp
local address = 192.168.10.10:57926
remote address = 192.168.10.20:50055
-- 2/6/2022, 18:00:14.121 Network: received 15 of 15 bytes via tcp
local address = 192.168.10.10:57926
remote address = 192.168.10.20:50055
-- 2/6/2022, 18:00:14.122 Protocol: received reply
message type = 2 (reply)
compression status = 0 (not compressed; do not compress response, if any)
message size = 29
request id = 3
reply status = 0 (ok)
-- 2/6/2022, 18:00:14.124 Network: received 14 of 14 bytes via tcp
local address = 192.168.10.10:57926
remote address = 192.168.10.20:50055
-- 2/6/2022, 18:00:14.125 Network: received 12 of 12 bytes via tcp
local address = 192.168.10.10:57926
remote address = 192.168.10.20:50055
-- 2/6/2022, 18:00:14.125 Protocol: received reply
message type = 2 (reply)
compression status = 0 (not compressed; do not compress response, if any)
message size = 26
request id = 4
reply status = 0 (ok)
-- 2/6/2022, 18:00:14.126 Network: received 14 of 14 bytes via tcp
local address = 192.168.10.10:57926
remote address = 192.168.10.20:50055
-- 2/6/2022, 18:00:14.127 Network: received 13 of 13 bytes via tcp
local address = 192.168.10.10:57926
remote address = 192.168.10.20:50055
-- 2/6/2022, 18:00:14.128 Protocol: received reply
message type = 2 (reply)
compression status = 0 (not compressed; do not compress response, if any)
message size = 27
request id = 5
reply status = 0 (ok)
-- 2/6/2022, 18:00:14.130 Protocol: sending request
message type = 0 (request)
compression status = 0 (not compressed; do not compress response, if any)
message size = 75
request id = 6
identity = Glacier2/router
facet =
operation = getServerProxy
mode = 1 (nonmutating)
context = secret/xxxx
-- 2/6/2022, 18:00:14.131 Network: sent 75 of 75 bytes via tcp
local address = 192.168.10.10:57926
remote address = 192.168.10.20:50055
-- 2/6/2022, 18:00:14.132 Network: received 14 of 14 bytes via tcp
local address = 192.168.10.10:57926
remote address = 192.168.10.20:50055
-- 2/6/2022, 18:00:14.133 Network: received 13 of 13 bytes via tcp
local address = 192.168.10.10:57926
remote address = 192.168.10.20:50055
-- 2/6/2022, 18:00:14.133 Protocol: received reply
message type = 2 (reply)
compression status = 0 (not compressed; do not compress response, if any)
message size = 27
request id = 6
reply status = 0 (ok)
1 minute stay there and then disconnected
-- 2/6/2022, 18:01:14.149 Protocol: sending close connection
message type = 4 (close connection)
compression status = 0 (not compressed; do not compress response, if any)
message size = 14
-- 2/6/2022, 18:01:14.150 Network: sent 14 of 14 bytes via tcp
local address = 192.168.10.10:57926
remote address = 192.168.10.20:50055
-- 2/6/2022, 18:01:14.158 Network: closed tcp connection
local address = 192.168.10.10:57926
remote address = 192.168.10.20:50055
Thanks! I get back with any news.
Hi Normando,
Can you post you glacier2 configuration, and let us know what version are you using?
Seems the glacier2 session timeouts and gets destroyed by the router.
const connection = router.ice_getCachedConnection();
if(timeout > 0)
{
connection.setACM(timeout, undefined, Ice.ACMHeartbeat.HeartbeatAlways);
}
The intent of the above code is to keep the session alive by sending heartbeat (validate connection messages), but those doesn't show up in you glacier2 tracing, can you print the value of timeout
variable to see if setACM
is actually being setup?
Hi Jose.
Yes, this is the config:
Glacier2.Client.Endpoints=tcp -h 192.168.10.20 -p 50055
Glacier2.SessionTimeout=60
Glacier2.CryptPasswords=passwords.txt
[murmur@vm-produccion ~]$ glacier2router -v
3.7.7
And i can't get timeout because I get this error and I don't know why:
::Ice::NoEndpointException
proxy: ""
This is my latest test code. I give up
const iceOptions = new Ice.InitializationData();
iceOptions.properties = Ice.createProperties([], iceOptions.properties);
iceOptions.properties.setProperty("Ice.Default.EncodingVersion", "1.0");
iceOptions.properties.setProperty("Ice.ImplicitContext", "Shared");
//iceOptions.properties.setProperty("Ice.Trace.Network", "3");
//iceOptions.properties.setProperty("Ice.Trace.Protocol", "1");
iceOptions.properties.setProperty("Ice.Default.Router", "Glacier2/router:tcp -p 50055 -h 192.168.10.20");
communicator = Ice.initialize(iceOptions);
communicator.getImplicitContext().put("secret", 'xxx');
const router = await Glacier2.RouterPrx.checkedCast(communicator.getDefaultRouter());
const session = await router.createSession("magic", "pink");
console.log('hhhhhh')
const [timeout, category, adapter] = await Promise.all(
[
router.getACMTimeout(),
router.getCategoryForClient(),
router.ice_getCommunicator().createObjectAdapterWithRouter("", router)
]);
const connection = router.ice_getCachedConnection();
console.log(timeout)
if(timeout > 0)
{
connection.setACM(timeout, undefined, Ice.ACMHeartbeat.HeartbeatAlways);
}
connection.setCloseCallback(() => console.log("Connection lost"));
proxy = await Murmur.MetaPrx.checkedCast(communicator.stringToProxy("Meta:tcp -h 127.0.0.1 -p 6502")); // proxy
...
Looking at the log you posted before, getACMTimeout
succeed, the log shows the request was send and the reply was received.
-- 2/6/2022, 18:00:14.111 Protocol: sending request
message type = 0 (request)
compression status = 0 (not compressed; do not compress response, if any)
message size = 74
request id = 3
identity = Glacier2/router
facet =
operation = getACMTimeout
mode = 1 (nonmutating)
context = secret/xxxx
-- 2/6/2022, 18:00:14.112 Network: sent 74 of 74 bytes via tcp
local address = 192.168.10.10:57926
remote address = 192.168.10.20:50055
...
-- 2/6/2022, 18:00:14.121 Network: received 14 of 14 bytes via tcp
local address = 192.168.10.10:57926
remote address = 192.168.10.20:50055
-- 2/6/2022, 18:00:14.121 Network: received 15 of 15 bytes via tcp
local address = 192.168.10.10:57926
remote address = 192.168.10.20:50055
-- 2/6/2022, 18:00:14.122 Protocol: received reply
message type = 2 (reply)
compression status = 0 (not compressed; do not compress response, if any)
message size = 29
request id = 3
reply status = 0 (ok)
Are you setting Glacier2.Server.Endpoints
in your glacier2 config? this is required when using callbacks
Setting Glacier2.Server.Endpoints enables an endpoint in Glacier2 that servers use when they invoke a callback on a client. (Note that you need not specify a port number for this property.) The endpoint you specify here must be accessible on the internal network so that back-end servers can connect to it. This endpoint should not be accessible from the external network to prevent malicious clients from flooding Glacier2's server endpoint with requests.
Hi Jose! No, but I added now, and the error goes off, and get the timeout of 60! Also no drop connection because now work heartBeat!
Thanks for the clarifications. Now I will try to fix an error get because Murmur callback, but seems the router is running ok.
I can confirm that routers run, executing some command like:
console.log(await proxy.getVersion())
and get
[communicator@vm-desarrollo murmur-api]$ node test.js
[ 1, 4, 0, '1.4.0' ]
But this command not require authentication from Murmur. But other commands require authentication, like this:
console.log(await proxy.getAllServers())
and get
[communicator@vm-desarrollo murmur-api]$ node test.js
::Murmur::InvalidSecretException
I supposed this is already configured in line
communicator = Ice.initialize(iceOptions);
communicator.getImplicitContext().put("secret", 'xxxx');
but seems no working through router. This was running when no use the router. Is there a way to configure proxy authentication through router?
Thanks Jose
Did you set Glacier2.Client.ForwardContext
and, or Glacier2.Server.ForwardContext
on your glacier2 configuration, I mentioned this before in https://github.com/zeroc-ice/ice/issues/1340#issuecomment-1030786096
But seems they are missing from your config. Without this glacier2 will not forward the context.
Jose, thank you very much! The callbacks runs like a charm!!!!!!
Regards!
Hi all. Sorry to file a bug with a question, but I can't found the correct way to fix my issue.
I was readed all examples at https://github.com/zeroc-ice/ice-demos/blob/3.7/js/Ice/bidir/ also #194
I am trying to get a callback from Murmur server with NodeJS client IN SAME SERVER (no remote server).
This is the ice from Murmur: https://mumble.sourceforge.io/slice/1.3.0/Murmur.html
And this is my testing code:
On Murmur's log I get:
<W>2022-02-05 17:25:56.183 Added Ice MetaCallback b2404fd8-9147-4809-8bee-02b1a62ed913 -o -e 1.0
but if I tried with a python client I get:
<W>2022-02-05 17:26:14.699 Added Ice MetaCallback 364F6850-3F07-4F8B-A4F0-F8D46316B75A -o -e 1.0:tcp -h 127.0.0.1 -p 40397 -t 5000
Also I was installed Glacier2 in Murmur server, but I can´t figure how to write the code based on my code and
https://github.com/zeroc-ice/ice-demos/tree/3.7/js/Glacier2/simpleChat
Appreciate any help or guidelines. I am completely lost
Thanks