Coverage Summary for Class: ReasonCode (org.ethereum.net.message)
Class |
Class, %
|
Method, %
|
Line, %
|
ReasonCode |
0%
(0/1)
|
0%
(0/4)
|
0%
(0/26)
|
1 /*
2 * This file is part of RskJ
3 * Copyright (C) 2017 RSK Labs Ltd.
4 * (derived from ethereumJ library, Copyright (c) 2016 <ether.camp>)
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 package org.ethereum.net.message;
21
22 import java.util.HashMap;
23 import java.util.Map;
24
25 /**
26 * Reason is an optional integer specifying one
27 * of a number of reasons for disconnect
28 */
29 public enum ReasonCode {
30
31 /**
32 * [0x00] Disconnect request by other peer
33 */
34 REQUESTED(0x00),
35
36 /**
37 * [0x01]
38 */
39 TCP_ERROR(0x01),
40
41 /**
42 * [0x02] Packets can not be parsed
43 */
44 BAD_PROTOCOL(0x02),
45
46 /**
47 * [0x03] This peer is too slow or delivers unreliable data
48 */
49 USELESS_PEER(0x03),
50
51 /**
52 * [0x04] Already too many connections with other peers
53 */
54 TOO_MANY_PEERS(0x04),
55
56
57 /**
58 * [0x05] Already have a running connection with this peer
59 */
60 DUPLICATE_PEER(0x05),
61
62 /**
63 * [0x06] Version of the p2p protocol is not the same as ours
64 */
65 INCOMPATIBLE_PROTOCOL(0x06),
66
67 /**
68 * [0x07]
69 */
70 NULL_IDENTITY(0x07),
71
72 /**
73 * [0x08] Peer quit voluntarily
74 */
75 PEER_QUITING(0x08),
76
77 UNEXPECTED_IDENTITY(0x09),
78
79 LOCAL_IDENTITY(0x0A),
80
81 PING_TIMEOUT(0x0B),
82
83 USER_REASON(0x10),
84
85 UNEXPECTED_GENESIS(0x11),
86
87 /**
88 * [0xFF] Reason not specified
89 */
90 UNKNOWN(0xFF);
91
92 private int reason;
93
94 private static final Map<Integer, ReasonCode> intToTypeMap = new HashMap<>();
95
96 static {
97 for (ReasonCode type : ReasonCode.values()) {
98 intToTypeMap.put(type.reason, type);
99 }
100 }
101
102 private ReasonCode(int reason) {
103 this.reason = reason;
104 }
105
106 public static ReasonCode fromInt(int i) {
107 ReasonCode type = intToTypeMap.get(i);
108 if (type == null) {
109 return ReasonCode.UNKNOWN;
110 }
111 return type;
112 }
113
114 public byte asByte() {
115 return (byte) reason;
116 }
117 }