diff options
-rw-r--r-- | erts/epmd/test/epmd_SUITE.erl | 109 | ||||
-rw-r--r-- | lib/erl_interface/src/epmd/ei_epmd.h | 11 | ||||
-rw-r--r-- | lib/erl_interface/src/epmd/epmd_port.c | 71 | ||||
-rw-r--r-- | lib/erl_interface/src/epmd/epmd_publish.c | 68 | ||||
-rw-r--r-- | lib/jinterface/java_src/com/ericsson/otp/erlang/OtpEpmd.java | 161 | ||||
-rw-r--r-- | lib/kernel/src/erl_epmd.erl | 86 | ||||
-rw-r--r-- | lib/kernel/src/erl_epmd.hrl | 17 |
7 files changed, 75 insertions, 448 deletions
diff --git a/erts/epmd/test/epmd_SUITE.erl b/erts/epmd/test/epmd_SUITE.erl index 91e09faf75..88980fec63 100644 --- a/erts/epmd/test/epmd_SUITE.erl +++ b/erts/epmd/test/epmd_SUITE.erl @@ -82,11 +82,8 @@ -define(REG_REPEAT_LIM,1000). % Message codes in epmd protocol --define(EPMD_ALIVE_REQ, $a). -define(EPMD_ALIVE2_REQ, $x). --define(EPMD_ALIVE_OK_RESP, $Y). -define(EPMD_ALIVE2_RESP, $y). --define(EPMD_PORT_REQ, $p). -define(EPMD_PORT_PLEASE2_REQ, $z). -define(EPMD_PORT2_RESP, $w). -define(EPMD_NAMES_REQ, $n). @@ -148,7 +145,7 @@ register_name(doc) -> ["Register a name"]; register_name(suite) -> []; -register_name(Config) when list(Config) -> +register_name(Config) when is_list(Config) -> ?line ok = epmdrun(), ?line {ok,Sock} = register_node("foobar"), ?line ok = close(Sock), % Unregister @@ -158,7 +155,7 @@ register_names_1(doc) -> ["Register and unregister two nodes"]; register_names_1(suite) -> []; -register_names_1(Config) when list(Config) -> +register_names_1(Config) when is_list(Config) -> ?line ok = epmdrun(), ?line {ok,Sock1} = register_node("foobar"), ?line {ok,Sock2} = register_node("foozap"), @@ -170,7 +167,7 @@ register_names_2(doc) -> ["Register and unregister two nodes"]; register_names_2(suite) -> []; -register_names_2(Config) when list(Config) -> +register_names_2(Config) when is_list(Config) -> ?line ok = epmdrun(), ?line {ok,Sock1} = register_node("foobar"), ?line {ok,Sock2} = register_node("foozap"), @@ -182,7 +179,7 @@ register_duplicate_name(doc) -> ["Two nodes with the same name"]; register_duplicate_name(suite) -> []; -register_duplicate_name(Config) when list(Config) -> +register_duplicate_name(Config) when is_list(Config) -> ?line ok = epmdrun(), ?line {ok,Sock} = register_node("foobar"), ?line error = register_node("foobar"), @@ -192,22 +189,9 @@ register_duplicate_name(Config) when list(Config) -> % Internal function to register a node name, no close, i.e. unregister register_node(Name) -> - register_node(Name,?DUMMY_PORT). - -register_node(Name, Port) -> - case send_req([?EPMD_ALIVE_REQ, put16(Port), Name]) of - {ok,Sock} -> - case recv(Sock,3) of - {ok, [?EPMD_ALIVE_OK_RESP,_D1,_D0]} -> - {ok,Sock}; - Other -> - test_server:format("recv on sock ~w: ~p~n", - [Sock,Other]), - error - end; - error -> - error - end. + register_node_v2(?DUMMY_PORT,$M,0,5,5,Name,""). +register_node(Name,Port) -> + register_node_v2(Port,$M,0,5,5,Name,""). register_node_v2(Port, NodeType, Prot, HVsn, LVsn, Name, Extra) -> Req = [?EPMD_ALIVE2_REQ, put16(Port), NodeType, Prot, @@ -254,7 +238,7 @@ parse_port2_resp(Resp) -> hvsn=HVsn,lvsn=LVsn, node_name=binary_to_list(NodeName), extra=binary_to_list(Extra)}}; - Other -> + _Other -> test_server:format("invalid port2 resp: ~p~n", [Resp]), error @@ -266,7 +250,7 @@ name_with_null_inside(doc) -> ["Register a name with a null char in it"]; name_with_null_inside(suite) -> []; -name_with_null_inside(Config) when list(Config) -> +name_with_null_inside(Config) when is_list(Config) -> ?line ok = epmdrun(), ?line error = register_node("foo\000bar"), ok. @@ -277,11 +261,9 @@ name_null_terminated(doc) -> ["Register a name with terminating null byte"]; name_null_terminated(suite) -> []; -name_null_terminated(Config) when list(Config) -> +name_null_terminated(Config) when is_list(Config) -> ?line ok = epmdrun(), - ?line {ok,Sock} = register_node("foobar\000"), - ?line error = register_node("foobar"), - ?line ok = close(Sock), % Unregister + ?line error = register_node("foobar\000"), ok. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -290,7 +272,7 @@ stupid_names_req(doc) -> ["Read names from epmd in a stupid way"]; stupid_names_req(suite) -> []; -stupid_names_req(Config) when list(Config) -> +stupid_names_req(Config) when is_list(Config) -> Dog = ?config(watchdog, Config), test_server:timetrap_cancel(Dog), LongDog = test_server:timetrap(?MEDIUM_TEST_TIMEOUT), @@ -394,15 +376,15 @@ get_port_nr(doc) -> ["Register a name on a port and ask about port nr"]; get_port_nr(suite) -> []; -get_port_nr(Config) when list(Config) -> - port_request([?EPMD_PORT_REQ,"foo"]). +get_port_nr(Config) when is_list(Config) -> + port_request([?EPMD_PORT_PLEASE2_REQ,"foo"]). slow_get_port_nr(doc) -> ["Register with slow write and ask about port nr"]; slow_get_port_nr(suite) -> []; -slow_get_port_nr(Config) when list(Config) -> - port_request([?EPMD_PORT_REQ,d,$f,d,$o,d,$o]). +slow_get_port_nr(Config) when is_list(Config) -> + port_request([?EPMD_PORT_PLEASE2_REQ,d,$f,d,$o,d,$o]). % Internal function used above @@ -413,9 +395,18 @@ port_request(M) -> ?line {ok,RSock} = register_node("foo", Port), ?line {ok,Sock} = connect(), ?line ok = send(Sock,[size16(M),M]), - R = put16(Port), - ?line {ok,R} = recv(Sock, length(R)), - ?line ok = close(RSock), + ?line case recv_until_sock_closes(Sock) of + {ok, Resp} -> + ?line close(RSock), + ?line {ok,Rec} = parse_port2_resp(Resp), + ?line Port = Rec#node_info.port, + ok; + Other -> + ?line close(RSock), + ?line test_server:format("recv on sock ~w: ~p~n", + [Sock,Other]), + ?line throw({error,Other}) + end, ok. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -424,7 +415,7 @@ unregister_others_name_1(doc) -> ["Unregister name of other node"]; unregister_others_name_1(suite) -> []; -unregister_others_name_1(Config) when list(Config) -> +unregister_others_name_1(Config) when is_list(Config) -> ?line ok = epmdrun(), ?line {ok,RSock} = register_node("foo"), ?line {ok,Sock} = connect(), @@ -441,7 +432,7 @@ unregister_others_name_2(doc) -> ["Unregister name of other node"]; unregister_others_name_2(suite) -> []; -unregister_others_name_2(Config) when list(Config) -> +unregister_others_name_2(Config) when is_list(Config) -> ?line ok = epmdrun(), ?line {ok,Sock} = connect(), M = [?EPMD_STOP_REQ,"xxx42"], @@ -456,7 +447,7 @@ register_overflow(doc) -> ["Register too many, clean and redo 10 times"]; register_overflow(suite) -> []; -register_overflow(Config) when list(Config) -> +register_overflow(Config) when is_list(Config) -> Dog = ?config(watchdog, Config), test_server:timetrap_cancel(Dog), LongDog = test_server:timetrap(?LONG_TEST_TIMEOUT), @@ -546,7 +537,7 @@ no_data(doc) -> ["Open but send no data"]; no_data(suite) -> []; -no_data(Config) when list(Config) -> +no_data(Config) when is_list(Config) -> ?line ok = epmdrun(), ?line {ok,Sock} = connect(), sleep(?LONG_PAUSE), @@ -559,7 +550,7 @@ one_byte(doc) -> ["Send one byte only"]; one_byte(suite) -> []; -one_byte(Config) when list(Config) -> +one_byte(Config) when is_list(Config) -> ?line ok = epmdrun(), ?line {ok,Sock} = connect(), ?line ok = send(Sock,[0]), @@ -573,7 +564,7 @@ two_bytes(doc) -> ["Send packet size only"]; two_bytes(suite) -> []; -two_bytes(Config) when list(Config) -> +two_bytes(Config) when is_list(Config) -> ?line ok = epmdrun(), ?line {ok,Sock} = connect(), ?line ok = send(Sock,[put16(3)]), @@ -587,7 +578,7 @@ partial_packet(doc) -> ["Got only part of a packet"]; partial_packet(suite) -> []; -partial_packet(Config) when list(Config) -> +partial_packet(Config) when is_list(Config) -> ?line ok = epmdrun(), ?line {ok,Sock} = connect(), ?line ok = send(Sock,[put16(100),"only a few bytes"]), @@ -601,7 +592,7 @@ zero_length(doc) -> ["Invalid zero packet size"]; zero_length(suite) -> []; -zero_length(Config) when list(Config) -> +zero_length(Config) when is_list(Config) -> ?line ok = epmdrun(), ?line {ok,Sock} = connect(), ?line ok = send(Sock,[0,0,0,0,0,0,0,0,0,0]), @@ -615,7 +606,7 @@ too_large(doc) -> ["Invalid large packet"]; too_large(suite) -> []; -too_large(Config) when list(Config) -> +too_large(Config) when is_list(Config) -> ?line ok = epmdrun(), ?line {ok,Sock} = connect(), Size = 63000, @@ -631,10 +622,11 @@ alive_req_too_small_1(doc) -> ["Try to register but not enough data"]; alive_req_too_small_1(suite) -> []; -alive_req_too_small_1(Config) when list(Config) -> +alive_req_too_small_1(Config) when is_list(Config) -> ?line ok = epmdrun(), ?line {ok,Sock} = connect(), - M = [?EPMD_ALIVE_REQ, 42], + M = [?EPMD_ALIVE2_REQ, put16(?DUMMY_PORT),$M,0, put16(5), + put16(5),put16(0)], ?line ok = send(Sock, [size16(M), M]), sleep(?MEDIUM_PAUSE), ?line closed = recv(Sock,1), @@ -646,10 +638,11 @@ alive_req_too_small_2(doc) -> ["Try to register but not enough data"]; alive_req_too_small_2(suite) -> []; -alive_req_too_small_2(Config) when list(Config) -> +alive_req_too_small_2(Config) when is_list(Config) -> ?line ok = epmdrun(), ?line {ok,Sock} = connect(), - M = [?EPMD_ALIVE_REQ, put16(?DUMMY_PORT)], + M = [?EPMD_ALIVE2_REQ, put16(?DUMMY_PORT),$M,0, put16(5), + put16(5)], ?line ok = send(Sock, [size16(M), M]), sleep(?MEDIUM_PAUSE), ?line closed = recv(Sock,1), @@ -661,7 +654,7 @@ alive_req_too_large(doc) -> ["Try to register but node name too large"]; alive_req_too_large(suite) -> []; -alive_req_too_large(Config) when list(Config) -> +alive_req_too_large(Config) when is_list(Config) -> ?line ok = epmdrun(), ?line {ok,Sock} = connect(), L = [ @@ -678,10 +671,12 @@ alive_req_too_large(Config) when list(Config) -> "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ], - M = [?EPMD_ALIVE_REQ, put16(?DUMMY_PORT), L], + S = length(lists:flatten(L)), + M = [?EPMD_ALIVE2_REQ, put16(?DUMMY_PORT),$M,0, put16(5), + put16(5), put16(S),L,put16(0)], ?line ok = send(Sock, [size16(M), M]), sleep(?MEDIUM_PAUSE), - ?line closed = recv(Sock,1), + ?line {ok,[?EPMD_ALIVE2_RESP,1]} = recv(Sock,2), ok. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -690,7 +685,7 @@ returns_valid_empty_extra(doc) -> ["Check that an empty extra is prefixed by a two byte length"]; returns_valid_empty_extra(suite) -> []; -returns_valid_empty_extra(Config) when list(Config) -> +returns_valid_empty_extra(Config) when is_list(Config) -> ?line ok = epmdrun(), ?line {ok,Sock} = register_node_v2(4711, 72, 0, 5, 5, "foo", []), ?line {ok,#node_info{extra=[]}} = port_please_v2("foo"), @@ -703,7 +698,7 @@ returns_valid_populated_extra_with_nulls(doc) -> ["Check a populated extra with embedded null characters"]; returns_valid_populated_extra_with_nulls(suite) -> []; -returns_valid_populated_extra_with_nulls(Config) when list(Config) -> +returns_valid_populated_extra_with_nulls(Config) when is_list(Config) -> ?line ok = epmdrun(), ?line {ok,Sock} = register_node_v2(4711, 72, 0, 5, 5, "foo", "ABC\000\000"), ?line {ok,#node_info{extra="ABC\000\000"}} = port_please_v2("foo"), @@ -858,9 +853,9 @@ send(Sock, SendSpec) -> send([], RevBytes, _Sock) -> {ok,RevBytes}; -send([Byte | Spec], RevBytes, Sock) when integer(Byte) -> +send([Byte | Spec], RevBytes, Sock) when is_integer(Byte) -> send(Spec, [Byte | RevBytes], Sock); -send([List | Spec], RevBytes, Sock) when list(List) -> +send([List | Spec], RevBytes, Sock) when is_list(List) -> case send(List, RevBytes, Sock) of {ok,Left} -> send(Spec, Left, Sock); diff --git a/lib/erl_interface/src/epmd/ei_epmd.h b/lib/erl_interface/src/epmd/ei_epmd.h index 40e5ece572..ccacfed244 100644 --- a/lib/erl_interface/src/epmd/ei_epmd.h +++ b/lib/erl_interface/src/epmd/ei_epmd.h @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 1998-2009. All Rights Reserved. + * Copyright Ericsson AB 1998-2010. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in @@ -40,20 +40,13 @@ #define EI_MYPROTO 0 /* tcp/ip */ #endif -/* epmd r3 protocol */ -#ifndef EI_EPMD_ALIVE_REQ -#define EI_EPMD_ALIVE_REQ 'a' -#define EI_EPMD_ALIVE_OK_RESP 'Y' -#define EI_EPMD_PORT_REQ 'p' -#define EI_EPMD_STOP_REQ 's' -#endif - /* epmd r4 */ #ifndef EI_EPMD_ALIVE2_REQ #define EI_EPMD_ALIVE2_REQ 120 #define EI_EPMD_ALIVE2_RESP 121 #define EI_EPMD_PORT2_REQ 122 #define EI_EPMD_PORT2_RESP 119 +#define EI_EPMD_STOP_REQ 's' #endif /* internal functions */ diff --git a/lib/erl_interface/src/epmd/epmd_port.c b/lib/erl_interface/src/epmd/epmd_port.c index 663b38d2d4..3dd3da7aae 100644 --- a/lib/erl_interface/src/epmd/epmd_port.c +++ b/lib/erl_interface/src/epmd/epmd_port.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 1998-2009. All Rights Reserved. + * Copyright Ericsson AB 1998-2010. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in @@ -92,64 +92,6 @@ int ei_epmd_connect_tmo(struct in_addr *inaddr, unsigned ms) return sd; } -/* get the given node's listen port using old epmd protocol */ -static int ei_epmd_r3_port (struct in_addr *addr, const char *alive, - unsigned ms) -{ - char buf[EPMDBUF]; - char *s = buf; - int len = strlen(alive) + 1; - int fd; - int port; - int res; -#if defined(VXWORKS) - char ntoabuf[32]; -#endif - - put16be(s,len); - put8(s,EI_EPMD_PORT_REQ); - strcpy(s,alive); - - /* connect to epmd */ - if ((fd = ei_epmd_connect_tmo(addr,ms)) < 0) - { - /* ei_epmd_connect_tmo() sets erl_errno */ - return -1; - } - - if ((res = ei_write_fill_t(fd, buf, len+2, ms)) != len+2) { - closesocket(fd); - erl_errno = (res == -2) ? ETIMEDOUT : EIO; - return -1; - } - -#ifdef VXWORKS - /* FIXME use union/macro for level. Correct level? */ - if (ei_tracelevel > 2) { - inet_ntoa_b(*addr,ntoabuf); - EI_TRACE_CONN2("ei_epmd_r3_port", - "-> PORT_REQ alive=%s ip=%s",alive,ntoabuf); - } -#else - EI_TRACE_CONN2("ei_epmd_r3_port", - "-> PORT_REQ alive=%s ip=%s",alive,inet_ntoa(*addr)); -#endif - - if ((res = ei_read_fill_t(fd, buf, 2, ms)) != 2) { - EI_TRACE_ERR0("ei_epmd_r3_port","<- CLOSE"); - closesocket(fd); - erl_errno = (res == -2) ? ETIMEDOUT : EIO; - return -1; - } - closesocket(fd); - s = buf; - port = get16be(s); - - EI_TRACE_CONN1("ei_epmd_r3_port","<- PORT_RESP port=%d",port); - - return port; -} - static int ei_epmd_r4_port (struct in_addr *addr, const char *alive, int *dist, unsigned ms) { @@ -285,15 +227,6 @@ int ei_epmd_port_tmo (struct in_addr *addr, const char *alive, int *dist, { int i; - /* try the new one first, then the old one */ - i = ei_epmd_r4_port(addr,alive,dist,ms); - - /* -2: new protocol not understood */ - if (i == -2) { - *dist = 0; - i = ei_epmd_r3_port(addr,alive,ms); - } - - return i; + return ei_epmd_r4_port(addr,alive,dist,ms); } diff --git a/lib/erl_interface/src/epmd/epmd_publish.c b/lib/erl_interface/src/epmd/epmd_publish.c index 09b3dce43b..a9b8727747 100644 --- a/lib/erl_interface/src/epmd/epmd_publish.c +++ b/lib/erl_interface/src/epmd/epmd_publish.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 1998-2009. All Rights Reserved. + * Copyright Ericsson AB 1998-2010. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in @@ -55,62 +55,6 @@ /* publish our listen port and alive name */ /* return the (useless) creation number */ -static int ei_epmd_r3_publish (int port, const char *alive, unsigned ms) -{ - char buf[EPMDBUF]; - char *s = buf; - int fd; - int len = strlen(alive) + 3; - int res,creation; - - s = buf; - put16be(s,len); - put8(s,EI_EPMD_ALIVE_REQ); - put16be(s,port); - strcpy(s, alive); - - if ((fd = ei_epmd_connect_tmo(NULL,ms)) < 0) return fd; - - if ((res = ei_write_fill_t(fd, buf, len+2, ms)) != len+2) { - closesocket(fd); - erl_errno = (res == -2) ? ETIMEDOUT : EIO; - return -1; - } - - EI_TRACE_CONN2("ei_epmd_r3_publish", - "-> ALIVE_REQ alive=%s port=%d",alive,port); - - if ((res = ei_read_fill_t(fd, buf, 3, ms)) != 3) { - closesocket(fd); - erl_errno = (res == -2) ? ETIMEDOUT : EIO; - return -1; - } - - s = buf; - if ((res=get8(s)) != EI_EPMD_ALIVE_OK_RESP) { - EI_TRACE_ERR1("ei_epmd_r3_publish", - "<- ALIVE_NOK result=%d (failure)",res); - closesocket(fd); - erl_errno = EIO; - return -1; - } - - creation = get16be(s); - - EI_TRACE_CONN1("ei_epmd_r3_publish","<- ALIVE_OK creation=%d",creation); - - /* Don't close fd here! It keeps us registered with epmd */ - - /* probably should save fd so we can close it later... */ - /* epmd_saveconn(OPEN,fd,alive); */ - - /* return the creation number, for no good reason */ - /* return creation; */ - - /* no! return the descriptor */ - return fd; -} - /* publish our listen port and alive name */ /* return the (useless) creation number */ /* this protocol is a lot more complex than the old one */ @@ -200,15 +144,7 @@ int ei_epmd_publish(int port, const char *alive) int ei_epmd_publish_tmo(int port, const char *alive, unsigned ms) { - int i; - - /* try the new one first, then the old one */ - i = ei_epmd_r4_publish(port,alive, ms); - - /* -2: new protocol not understood */ - if (i == -2) i = ei_epmd_r3_publish(port,alive, ms); - - return i; + return ei_epmd_r4_publish(port,alive, ms);; } diff --git a/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpEpmd.java b/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpEpmd.java index 3bb678c2cc..deac528133 100644 --- a/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpEpmd.java +++ b/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpEpmd.java @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 2000-2009. All Rights Reserved. + * Copyright Ericsson AB 2000-2010. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in @@ -71,11 +71,6 @@ public class OtpEpmd { // common values private static final byte stopReq = (byte) 115; - // version specific value - private static final byte port3req = (byte) 112; - private static final byte publish3req = (byte) 97; - private static final byte publish3ok = (byte) 89; - private static final byte port4req = (byte) 122; private static final byte port4resp = (byte) 119; private static final byte publish4req = (byte) 120; @@ -123,11 +118,7 @@ public class OtpEpmd { * if there was no response from the name server. */ public static int lookupPort(final AbstractNode node) throws IOException { - try { return r4_lookupPort(node); - } catch (final IOException e) { - return r3_lookupPort(node); - } } /** @@ -147,11 +138,7 @@ public class OtpEpmd { throws IOException { Socket s = null; - try { - s = r4_publish(node); - } catch (final IOException e) { - s = r3_publish(node); - } + s = r4_publish(node); node.setEpmd(s); @@ -196,67 +183,6 @@ public class OtpEpmd { } } - private static int r3_lookupPort(final AbstractNode node) - throws IOException { - int port = 0; - Socket s = null; - - try { - final OtpOutputStream obuf = new OtpOutputStream(); - s = new Socket(node.host(), EpmdPort.get()); - - // build and send epmd request - // length[2], tag[1], alivename[n] (length = n+1) - obuf.write2BE(node.alive().length() + 1); - obuf.write1(port3req); - obuf.writeN(node.alive().getBytes()); - - // send request - obuf.writeTo(s.getOutputStream()); - - if (traceLevel >= traceThreshold) { - System.out.println("-> LOOKUP (r3) " + node); - } - - // receive and decode reply - final byte[] tmpbuf = new byte[100]; - - s.getInputStream().read(tmpbuf); - final OtpInputStream ibuf = new OtpInputStream(tmpbuf, 0); - - port = ibuf.read2BE(); - } catch (final IOException e) { - if (traceLevel >= traceThreshold) { - System.out.println("<- (no response)"); - } - throw new IOException("Nameserver not responding on " + node.host() - + " when looking up " + node.alive()); - } catch (final OtpErlangDecodeException e) { - if (traceLevel >= traceThreshold) { - System.out.println("<- (invalid response)"); - } - throw new IOException("Nameserver not responding on " + node.host() - + " when looking up " + node.alive()); - } finally { - try { - if (s != null) { - s.close(); - } - } catch (final IOException e) { /* ignore close errors */ - } - s = null; - } - - if (traceLevel >= traceThreshold) { - if (port == 0) { - System.out.println("<- NOT FOUND"); - } else { - System.out.println("<- PORT " + port); - } - } - return port; - } - private static int r4_lookupPort(final AbstractNode node) throws IOException { int port = 0; @@ -288,8 +214,6 @@ public class OtpEpmd { final int n = s.getInputStream().read(tmpbuf); if (n < 0) { - // this was an r3 node => not a failure (yet) - s.close(); throw new IOException("Nameserver not responding on " + node.host() + " when looking up " + node.alive()); @@ -342,81 +266,13 @@ public class OtpEpmd { return port; } - private static Socket r3_publish(final OtpLocalNode node) - throws IOException { - Socket s = null; - - try { - final OtpOutputStream obuf = new OtpOutputStream(); - s = new Socket((String) null, EpmdPort.get()); - - obuf.write2BE(node.alive().length() + 3); - - obuf.write1(publish3req); - obuf.write2BE(node.port()); - obuf.writeN(node.alive().getBytes()); - - // send request - obuf.writeTo(s.getOutputStream()); - if (traceLevel >= traceThreshold) { - System.out.println("-> PUBLISH (r3) " + node + " port=" - + node.port()); - } - - final byte[] tmpbuf = new byte[100]; - - final int n = s.getInputStream().read(tmpbuf); - - if (n < 0) { - s.close(); - if (traceLevel >= traceThreshold) { - System.out.println("<- (no response)"); - } - return null; - } - - final OtpInputStream ibuf = new OtpInputStream(tmpbuf, 0); - - if (ibuf.read1() == publish3ok) { - node.creation = ibuf.read2BE(); - if (traceLevel >= traceThreshold) { - System.out.println("<- OK"); - } - return s; // success - don't close socket - } - } catch (final IOException e) { - // epmd closed the connection = fail - if (s != null) { - s.close(); - } - if (traceLevel >= traceThreshold) { - System.out.println("<- (no response)"); - } - throw new IOException("Nameserver not responding on " + node.host() - + " when publishing " + node.alive()); - } catch (final OtpErlangDecodeException e) { - if (s != null) { - s.close(); - } - if (traceLevel >= traceThreshold) { - System.out.println("<- (invalid response)"); - } - throw new IOException("Nameserver not responding on " + node.host() - + " when publishing " + node.alive()); - } - - if (s != null) { - s.close(); - } - return null; // failure - } - /* - * this function will get an exception if it tries to talk to an r3 epmd, or - * if something else happens that it cannot forsee. In both cases we return - * an exception (and the caller should try again, using the r3 protocol). If - * we manage to successfully communicate with an r4 epmd, we return either - * the socket, or null, depending on the result. + * this function will get an exception if it tries to talk to a + * very old epmd, or if something else happens that it cannot + * forsee. In both cases we return an exception. We no longer + * support r3, so the exception is fatal. If we manage to + * successfully communicate with an r4 epmd, we return either the + * socket, or null, depending on the result. */ private static Socket r4_publish(final OtpLocalNode node) throws IOException { @@ -454,7 +310,6 @@ public class OtpEpmd { final int n = s.getInputStream().read(tmpbuf); if (n < 0) { - // this was an r3 node => not a failure (yet) if (s != null) { s.close(); } diff --git a/lib/kernel/src/erl_epmd.erl b/lib/kernel/src/erl_epmd.erl index 4a22637304..91af49f303 100644 --- a/lib/kernel/src/erl_epmd.erl +++ b/lib/kernel/src/erl_epmd.erl @@ -210,19 +210,6 @@ open({A,B,C,D,E,F,G,H}=EpmdAddr, Timeout) when ?ip6(A,B,C,D,E,F,G,H) -> close(Socket) -> gen_tcp:close(Socket). - -do_register_node_v0(NodeName, TcpPort) -> - case open() of - {ok, Socket} -> - Name = cstring(NodeName), - Len = 1+2+length(Name), - gen_tcp:send(Socket, [?int16(Len), ?EPMD_ALIVE, - ?int16(TcpPort), Name]), - wait_for_reg_reply_v0(Socket, []); - Error -> - Error - end. - do_register_node(NodeName, TcpPort) -> case open() of {ok, Socket} -> @@ -240,14 +227,7 @@ do_register_node(NodeName, TcpPort) -> Name, ?int16(Elen), Extra]), - case wait_for_reg_reply(Socket, []) of - {error, epmd_close} -> - %% could be old epmd; try old protocol -% erlang:display('trying old'), - do_register_node_v0(NodeName, TcpPort); - Other -> - Other - end; + wait_for_reg_reply(Socket, []); Error -> Error end. @@ -305,41 +285,9 @@ wait_for_reg_reply(Socket, SoFar) -> {error, no_reg_reply_from_epmd} end. -wait_for_reg_reply_v0(Socket, SoFar) -> - receive - {tcp, Socket, Data0} -> - case SoFar ++ Data0 of - [$Y, A, B] -> - {alive, Socket, ?u16(A, B)}; - Data when length(Data) < 3 -> - wait_for_reg_reply(Socket, Data); - Garbage -> - {error, {garbage_from_epmd, Garbage}} - end; - {tcp_closed, Socket} -> - {error, duplicate_name} % A guess -- the most likely reason. - after 10000 -> - gen_tcp:close(Socket), - {error, no_reg_reply_from_epmd} - end. %% %% Lookup a node "Name" at Host %% -get_port_v0(Node, EpmdAddress) -> - case open(EpmdAddress) of - {ok, Socket} -> - Name = cstring(Node), - Len = 1+length(Name), - gen_tcp:send(Socket, [?int16(Len),?EPMD_PORT_PLEASE, Name]), - wait_for_port_reply_v0(Socket, []); - _Error -> - ?port_please_failure(), - noport - end. - -%%% Not used anymore -%%% get_port(Node, EpmdAddress) -> -%%% get_port(Node, EpmdAddress, infinity). get_port(Node, EpmdAddress, Timeout) -> case open(EpmdAddress, Timeout) of @@ -347,40 +295,12 @@ get_port(Node, EpmdAddress, Timeout) -> Name = to_string(Node), Len = 1+length(Name), gen_tcp:send(Socket, [?int16(Len),?EPMD_PORT_PLEASE2_REQ, Name]), - Reply = wait_for_port_reply(Socket, []), - case Reply of - closed -> - get_port_v0(Node, EpmdAddress); - Other -> - Other - end; + wait_for_port_reply(Socket, []); _Error -> ?port_please_failure2(_Error), noport end. -wait_for_port_reply_v0(Socket, SoFar) -> - receive - {tcp, Socket, Data0} -> -% io:format("got ~p~n", [Data0]), - case SoFar ++ Data0 of - [A, B] -> - wait_for_close(Socket, {port, ?u16(A, B), 0}); -% wait_for_close(Socket, {port, ?u16(A, B)}); - Data when length(Data) < 2 -> - wait_for_port_reply_v0(Socket, Data); - Garbage -> - ?port_please_failure(), - {error, {garbage_from_epmd, Garbage}} - end; - {tcp_closed, Socket} -> - ?port_please_failure(), - noport - after 10000 -> - ?port_please_failure(), - gen_tcp:close(Socket), - noport - end. wait_for_port_reply(Socket, SoFar) -> receive @@ -487,8 +407,6 @@ wait_for_close(Socket, Reply) -> %% %% Creates a (flat) null terminated string from atom or list. %% -cstring(S) when is_atom(S) -> cstring(atom_to_list(S)); -cstring(S) when is_list(S) -> S ++ [0]. to_string(S) when is_atom(S) -> atom_to_list(S); to_string(S) when is_list(S) -> S. diff --git a/lib/kernel/src/erl_epmd.hrl b/lib/kernel/src/erl_epmd.hrl index 47ab6195d8..5a50fda508 100644 --- a/lib/kernel/src/erl_epmd.hrl +++ b/lib/kernel/src/erl_epmd.hrl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1998-2009. All Rights Reserved. +%% Copyright Ericsson AB 1998-2010. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -17,16 +17,13 @@ %% %CopyrightEnd% %% --define(EPMD_ALIVE, $a). --define(EPMD_PORT_PLEASE, $p). --define(EPMD_NAMES, $n). --define(EPMD_DUMP, $d). --define(EPMD_KILL, $k). --define(EPMD_STOP, $s). - --define(EPMD_ALIVE_OK, $Y). - -define(EPMD_ALIVE2_REQ, $x). -define(EPMD_PORT_PLEASE2_REQ, $z). -define(EPMD_ALIVE2_RESP, $y). -define(EPMD_PORT2_RESP, $w). +-define(EPMD_NAMES, $n). + +%% Commands used only by interactive client +-define(EPMD_DUMP, $d). +-define(EPMD_KILL, $k). +-define(EPMD_STOP, $s). |