public MasternodeAddress duplicate() { return new MasternodeAddress(getAddr(), getPort()); } }
public int calculateMessageSizeInBytes() { return getMessageSize(); }
public void setPort(int port) { unCache(); this.port = port; }
@Override protected void parse() throws ProtocolException { vin = new TransactionInput(params, null, payload, cursor); cursor += vin.getMessageSize(); address = new MasternodeAddress(params, payload, cursor, 0); cursor += address.getMessageSize(); pubKeyCollateralAddress = new PublicKey(params, payload, cursor); cursor += pubKeyCollateralAddress.getMessageSize(); pubKeyMasternode = new PublicKey(params, payload, cursor); cursor += pubKeyMasternode.getMessageSize(); sig = new MasternodeSignature(params, payload, cursor); cursor += sig.getMessageSize(); sigTime = readInt64(); protocolVersion = (int)readUint32(); lastPing = new MasternodePing(params, payload, cursor); cursor += lastPing.getMessageSize(); //nLastDsq = readInt64(); length = cursor - offset; }
UnsafeByteArrayOutputStream bos = new UnsafeByteArrayOutputStream((address.toString() + sigTime).length() + pubKeyCollateralAddress.getBytes().length + pubKeyMasternode.getBytes().length + ((Integer) protocolVersion).toString().getBytes().length); bos.write((address.toString() + sigTime).getBytes()); bos.write(pubKeyCollateralAddress.getBytes()); bos.write(pubKeyMasternode.getBytes()); strMessage = address.toString() + sigTime + Utils.HEX.encode(Utils.reverseBytes(pubKeyCollateralAddress.getId())) + Utils.HEX.encode(Utils.reverseBytes(pubKeyMasternode.getId())) + protocolVersion; message = strMessage.getBytes(); log.info("CMasternodeBroadcast::VerifySignature - sanitized strMessage: "+Utils.sanitizeString(strMessage)+", pubKeyCollateralAddress address: "+new Address(params, pubKeyCollateralAddress.getId()).toString()+", sig: %s\n" + if (address.getPort() != 9999) return false; } else if (address.getPort() == 9999) return false; log.info("mnb - Got updated entry for " + address.toString()); if (pmn.updateFromNewBroadcast(this)) { pmn.check();
public void remove(TransactionInput vin) { try { lock.lock(); //vector<CMasternode>::iterator it = vMasternodes.begin(); Iterator<Masternode> it = vMasternodes.iterator(); while (it.hasNext()) { Masternode mn = it.next(); if (mn.vin.equals(vin)){ log.info("masternode - CMasternodeMan: Removing Masternode %s "+mn.address.toString()+"- "+(size()-1)+" now"); //vMasternodes.remove(mn); it.remove(); queueOnSyncStatusChanged(); break; } } } finally { lock.unlock(); } } int size() { return vMasternodes.size(); }
log.info("mnb - Got NEW Masternode entry - {} - {} - {} - {} ", getHash().toString(), address.toString(), vin.toString(), sigTime); Masternode mn = new Masternode(this); context.masternodeManager.add(mn); boolean isLocal = address.getAddr().isSiteLocalAddress() || address.getAddr().isLoopbackAddress();
@Override public int hashCode() { return getAddr().hashCode() ^ port; }
@Override protected void bitcoinSerializeToStream(OutputStream stream) throws IOException { vin.bitcoinSerialize(stream); address.bitcoinSerialize(stream); pubKeyCollateralAddress.bitcoinSerialize(stream); pubKeyMasternode.bitcoinSerialize(stream); sig.bitcoinSerialize(stream); Utils.int64ToByteStreamLE(sigTime, stream); Utils.int64ToByteStreamLE(nLastDsq, stream); Utils.int64ToByteStreamLE(nTimeLastChecked, stream); Utils.int64ToByteStreamLE(nTimeLastPaid, stream); Utils.int64ToByteStreamLE(nTimeLastWatchdogVote, stream); Utils.uint32ToByteStreamLE(activeState.getValue(), stream); Utils.uint32ToByteStreamLE(nCacheCollateralBlock, stream); Utils.uint32ToByteStreamLE(nBlockLastPaid, stream); Utils.uint32ToByteStreamLE(protocolVersion, stream); Utils.uint32ToByteStreamLE(nPoSeBanScore, stream); Utils.uint32ToByteStreamLE(nPoSeBanHeight, stream); byte value [] = new byte[1]; value[0] = (byte)(fAllowMixingTx ? 1 : 0); stream.write(value); value[0] = (byte)(unitTest ? 1 : 0); stream.write(value); stream.write(new VarInt(mapGovernanceObjectsVotedOn.size()).encode()); for(Map.Entry<Sha256Hash, Integer> e: mapGovernanceObjectsVotedOn.entrySet()) { stream.write(e.getKey().getReversedBytes()); Utils.uint32ToByteStreamLE(e.getValue(), stream); } }
public static MasternodeAddress localhost(NetworkParameters params) { return new MasternodeAddress(InetAddresses.forString("127.0.0.1"), params.getPort()); }
boolean updateFromNewBroadcast(MasternodeBroadcast mnb) { if(mnb.sigTime > sigTime) { pubKeyMasternode = mnb.pubKeyMasternode; sigTime = mnb.sigTime; sig = mnb.sig; protocolVersion = mnb.protocolVersion; address = mnb.address.duplicate(); lastTimeChecked = 0; int nDoS = 0; if(mnb.lastPing == new MasternodePing(context) || (!mnb.lastPing.equals(new MasternodePing(context)) && mnb.lastPing.checkAndUpdate(false))) { lastPing = mnb.lastPing; context.masternodeManager.updateMasternodePing(lastPing); } return true; } return false; }
cursor += vin.getMessageSize(); address = new MasternodeAddress(params, payload, cursor, CoinDefinition.PROTOCOL_VERSION); cursor += address.getMessageSize();
boolean add(Masternode mn) { try { lock.lock(); if (!mn.isEnabled() && !mn.isPreEnabled()) return false; Masternode pmn = find(mn.vin); if (pmn == null) { log.info("masternode - MasternodeMan: Adding new Masternode "+mn.address.toString()+" - "+(size() + 1)+" now"); vMasternodes.add(mn); queueOnSyncStatusChanged(); return true; } return false; } finally { lock.unlock(); } }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; MasternodeAddress other = (MasternodeAddress) o; return other.getAddr().equals(getAddr()) && other.port == port; //TODO: including services and time could cause same peer to be added multiple times in collections }
@Override protected void bitcoinSerializeToStream(OutputStream stream) throws IOException { vin.bitcoinSerialize(stream); address.bitcoinSerialize(stream); pubKeyCollateralAddress.bitcoinSerialize(stream); pubKeyMasternode.bitcoinSerialize(stream); sig.bitcoinSerialize(stream); Utils.int64ToByteStreamLE(sigTime, stream); Utils.uint32ToByteStreamLE(protocolVersion, stream); lastPing.bitcoinSerialize(stream); Utils.int64ToByteStreamLE(nLastDsq, stream); }
public Masternode(Masternode other) { super(other.params); this.context = other.context; //LOCK(cs); this.vin = other.vin; //TODO: need to make copies of all these? this.address = new MasternodeAddress(other.address.getAddr(), other.address.getPort()); this.pubKeyCollateralAddress = other.pubKeyCollateralAddress.duplicate(); this.pubKeyMasternode = other.pubKeyMasternode.duplicate(); //These are good this.sig = other.sig.duplicate(); this.activeState = other.activeState; this.sigTime = other.sigTime; this.cacheInputAge = other.cacheInputAge; this.cacheInputAgeBlock = other.cacheInputAgeBlock; this.unitTest = other.unitTest; this.allowFreeTx = other.allowFreeTx; this.protocolVersion = other.protocolVersion; this.nLastDsq = other.nLastDsq; this.nScanningErrorCount = other.nScanningErrorCount; this.nLastScanningErrorBlockHeight = other.nLastScanningErrorBlockHeight; }
mn.activeState == Masternode.State.MASTERNODE_VIN_SPENT || (forceExpiredRemoval && mn.activeState == Masternode.State.MASTERNODE_EXPIRED)) { log.info("masternode-CMasternodeMan: Removing inactive Masternode {} - {} now", mn.address.toString(), size() - 1);
public InetSocketAddress toSocketAddress() { return new InetSocketAddress(getAddr(), port); }