mirror of https://github.com/hyperledger/besu
An enterprise-grade Java-based, Apache 2.0 licensed Ethereum client https://wiki.hyperledger.org/display/besu
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
2.3 KiB
46 lines
2.3 KiB
pragma solidity >=0.4.0 <0.6.0;
|
|
// THIS CONTRACT IS FOR TESTING PURPOSES ONLY
|
|
// DO NOT USE THIS CONTRACT IN PRODUCTION APPLICATIONS
|
|
|
|
contract SimplePermissioning {
|
|
struct Enode {
|
|
bytes32 enodeHigh;
|
|
bytes32 enodeLow;
|
|
bytes16 enodeHost;
|
|
uint16 enodePort;
|
|
}
|
|
mapping(bytes => Enode) private whitelist; // should there be a size for the whitelists?
|
|
|
|
function connectionAllowed(
|
|
bytes32 sourceEnodeHigh, bytes32 sourceEnodeLow, bytes16 sourceEnodeIp, uint16 sourceEnodePort,
|
|
bytes32 destinationEnodeHigh, bytes32 destinationEnodeLow, bytes16 destinationEnodeIp, uint16 destinationEnodePort)
|
|
public view returns (bytes32) {
|
|
if (enodeAllowed(sourceEnodeHigh, sourceEnodeLow, sourceEnodeIp, sourceEnodePort) &&
|
|
enodeAllowed(destinationEnodeHigh, destinationEnodeLow, destinationEnodeIp, destinationEnodePort)) {
|
|
return 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
|
|
} else {
|
|
return 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
|
|
}
|
|
}
|
|
function enodeAllowed(bytes32 sourceEnodeHigh, bytes32 sourceEnodeLow, bytes16 sourceEnodeIp, uint16 sourceEnodePort)
|
|
public view returns (bool){
|
|
bytes memory key = computeKey(sourceEnodeHigh, sourceEnodeLow, sourceEnodeIp, sourceEnodePort);
|
|
Enode storage whitelistSource = whitelist[key];
|
|
if (whitelistSource.enodeHost > 0) {
|
|
return true;
|
|
}
|
|
}
|
|
function addEnode(bytes32 enodeHigh, bytes32 enodeLow, bytes16 enodeIp, uint16 enodePort) public {
|
|
Enode memory newEnode = Enode(enodeHigh, enodeLow, enodeIp, enodePort);
|
|
bytes memory key = computeKey(enodeHigh, enodeLow, enodeIp, enodePort);
|
|
whitelist[key] = newEnode;
|
|
}
|
|
function removeEnode(bytes32 enodeHigh, bytes32 enodeLow, bytes16 enodeIp, uint16 enodePort) public {
|
|
bytes memory key = computeKey(enodeHigh, enodeLow, enodeIp, enodePort);
|
|
Enode memory zeros = Enode(bytes32(0), bytes32(0), bytes16(0), 0);
|
|
whitelist[key] = zeros;
|
|
}
|
|
function computeKey(bytes32 enodeHigh, bytes32 enodeLow, bytes16 enodeIp, uint16 enodePort) public pure returns (bytes memory) {
|
|
return abi.encode(enodeHigh, enodeLow, enodeIp, enodePort);
|
|
}
|
|
}
|
|
|