This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<FileHeader> | |
<SchemaVersion>3.2.1</SchemaVersion> | |
<Modality>I</Modality> | |
<InvoiceIssuerType>EM</InvoiceIssuerType> | |
<Batch> | |
<BatchIdentifier>A000000001234FAC2018</BatchIdentifier> | |
<InvoicesCount>1</InvoicesCount> | |
<TotalInvoicesAmount> | |
<TotalAmount>60.42</TotalAmount> | |
</TotalInvoicesAmount> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<fe:Facturae xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:fe="http://www.facturae.es/Facturae/2014/v3.2.1/Facturae"> | |
<FileHeader>...</FileHeader> | |
<Parties> | |
<SellerParty>...</SellerParty> | |
<BuyerParty>...</BuyerParty> | |
</Parties> | |
<Invoices> | |
<Invoice>...</Invoice> | |
</Invoices> | |
<ds:Signature xmlns:xades="http://uri.etsi.org/01903/v1.3.2#">...</ds:Signature> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void send(ObjectOutputStream stream, Object message) { | |
stream.writeObject(message); | |
stream.flush(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void propagate(Object message) { | |
new Thread(() -> { | |
for (InetAddress ip : peers) { | |
// Abrir socket hacia el nodo | |
Socket s = new Socket(); | |
s.connect( | |
new InetSocketAddress(ip, Cutrecoin.PORT), | |
Cutrecoin.TIMEOUT); | |
ObjectOutputStream outputStream = | |
new ObjectOutputStream(s.getOutputStream()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void sync() { | |
if (peers.isEmpty()) return; | |
propagate("getBlock=latest"); | |
propagate("getPendingTransactions"); | |
isSynced = true; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void onNewMessage(ObjectOutputStream outputStream, Object message) { | |
if (message instanceof Transaction) { | |
// Guardamos la transacción para minería | |
cutrecoin.addPendingTransaction((Transaction) message); | |
} else if (message instanceof Block) { | |
// Guardamos el bloque como candidato | |
Block b = (Block) message; | |
// Pedimos el bloque anterior al recibido | |
if (cutrecoin.addCandidateBlock(b)) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void acceptClient(Socket s) { | |
new Thread(() -> { | |
// Abrir streams de salida y entrada | |
// para objetos serializados de Java | |
ObjectOutputStream outputStream = | |
new ObjectOutputStream(s.getOutputStream()); | |
ObjectInputStream inputStream = | |
new ObjectInputStream(s.getInputStream()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void connectToServer(InetAddress ip) { | |
try { | |
Socket s = new Socket(); | |
s.connect( | |
new InetSocketAddress(ip, Cutrecoin.PORT), | |
Cutrecoin.TIMEOUT | |
); | |
s.close(); | |
// Añadir a la lista de nodos | |
for (InetAddress ia : peers) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
byte[] ip = subnetLocalhost.getAddress(); | |
for (int i=1; i<255; i++) { | |
ip[3] = (byte) i; | |
InetAddress address = InetAddress.getByAddress(ip); | |
// Comprobar que se añade esta máquina | |
if (address.equals(localhost)) continue; | |
// Intentar abrir socket TCP | |
connectToServer(address); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new Thread(() -> { | |
server = new ServerSocket(Cutrecoin.PORT); | |
while (isRunning) acceptClient(server.accept()); | |
}).start(); |