mirror of https://github.com/hyperledger/besu
[PAN-2433] Fix netty pipeline (#1257)
Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>pull/2/head
parent
110089fd63
commit
907bbb5299
@ -0,0 +1,20 @@ |
||||
/* |
||||
* Copyright 2019 ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
*/ |
||||
package tech.pegasys.pantheon.ethereum.p2p.netty.exceptions; |
||||
|
||||
public class BreachOfProtocolException extends RuntimeException { |
||||
|
||||
public BreachOfProtocolException(final String message) { |
||||
super(message); |
||||
} |
||||
} |
@ -0,0 +1,22 @@ |
||||
/* |
||||
* Copyright 2019 ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
*/ |
||||
package tech.pegasys.pantheon.ethereum.p2p.netty.exceptions; |
||||
|
||||
import tech.pegasys.pantheon.ethereum.p2p.wire.messages.DisconnectMessage.DisconnectReason; |
||||
|
||||
public class PeerDisconnectedException extends RuntimeException { |
||||
|
||||
public PeerDisconnectedException(final DisconnectReason reason) { |
||||
super("Peer disconnected for reason: " + reason.toString()); |
||||
} |
||||
} |
@ -0,0 +1,38 @@ |
||||
/* |
||||
* Copyright 2019 ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
*/ |
||||
package tech.pegasys.pantheon.ethereum.p2p.netty.testhelpers; |
||||
|
||||
import static org.mockito.ArgumentMatchers.any; |
||||
import static org.mockito.Mockito.mock; |
||||
import static org.mockito.Mockito.when; |
||||
|
||||
import io.netty.channel.ChannelFuture; |
||||
import io.netty.util.concurrent.Future; |
||||
import io.netty.util.concurrent.GenericFutureListener; |
||||
|
||||
public class NettyMocks { |
||||
public static ChannelFuture channelFuture(final boolean completeImmediately) { |
||||
ChannelFuture channelFuture = mock(ChannelFuture.class); |
||||
when(channelFuture.addListener(any())) |
||||
.then( |
||||
(invocation) -> { |
||||
if (completeImmediately) { |
||||
GenericFutureListener<Future<?>> listener = invocation.getArgument(0); |
||||
listener.operationComplete(mock(Future.class)); |
||||
} |
||||
return channelFuture; |
||||
}); |
||||
|
||||
return channelFuture; |
||||
} |
||||
} |
@ -0,0 +1,45 @@ |
||||
/* |
||||
* Copyright 2019 ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
*/ |
||||
package tech.pegasys.pantheon.ethereum.p2p.netty.testhelpers; |
||||
|
||||
import tech.pegasys.pantheon.ethereum.p2p.wire.SubProtocol; |
||||
|
||||
public class SubProtocolMock { |
||||
public static SubProtocol create() { |
||||
return create("eth"); |
||||
} |
||||
|
||||
public static SubProtocol create(final String name) { |
||||
return new SubProtocol() { |
||||
@Override |
||||
public String getName() { |
||||
return name; |
||||
} |
||||
|
||||
@Override |
||||
public int messageSpace(final int protocolVersion) { |
||||
return 8; |
||||
} |
||||
|
||||
@Override |
||||
public boolean isValidMessageCode(final int protocolVersion, final int code) { |
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public String messageName(final int protocolVersion, final int code) { |
||||
return INVALID_MESSAGE_NAME; |
||||
} |
||||
}; |
||||
} |
||||
} |
Loading…
Reference in new issue