Commit c8b2d8d1 authored by Benoit Lavenier's avatar Benoit Lavenier

[enh] Add send peer document

[enh] Add peer document serialization (to test)
[enh] Add known currencies and first block
[fix] Fix HTTP message to be more generic
parent dcb55a82
......@@ -74,17 +74,19 @@ public class NetworkPeerings {
for (; i < lines.length - 1; ) {
line = lines[i++].trim();
NetworkPeering.Endpoint ep = Endpoints.parse(line);
Preconditions.checkNotNull(ep, "Unaparsable endpoint: " + line);
Preconditions.checkNotNull(ep, "Unable to parse endpoint: " + line);
endpoints.add(ep);
}
result.setEndpoints(endpoints.toArray(new NetworkPeering.Endpoint[endpoints.size()]));
result.setSignature(lines[lines.length - 1]);
result.setStatus("UP");
return result;
}
catch(Exception e) {
throw new IOException(e.getMessage());
throw new IOException(e.getMessage(), e);
}
}
......
package org.duniter.core.client.model.bma.jackson;
/*
* #%L
* Duniter4j :: Core Client API
* %%
* Copyright (C) 2014 - 2017 EIS
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import org.duniter.core.client.model.bma.Endpoints;
import org.duniter.core.client.model.bma.NetworkPeering;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
/**
* Created by blavenie on 17/10/18.
*/
public class EndpointSerializer extends JsonSerializer<NetworkPeering.Endpoint> {
private static final Logger log = LoggerFactory.getLogger(EndpointSerializer.class);
private boolean debug;
public EndpointSerializer() {
this.debug = log.isDebugEnabled();
}
@Override
public void serialize(NetworkPeering.Endpoint endpoint, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) {
try {
jsonGenerator.writeString(endpoint.toString());
} catch(IOException e) {
// Unable to parse endpoint: continue (will skip this endpoint)
if (debug) {
log.warn(e.getMessage(), e); // link the exception
}
else {
log.debug(e.getMessage());
}
}
}
}
\ No newline at end of file
......@@ -61,6 +61,7 @@ public abstract class JacksonUtils extends SimpleModule {
// Network
module.addDeserializer(NetworkPeering.Endpoint.class, new EndpointDeserializer());
module.addSerializer(NetworkPeering.Endpoint.class, new EndpointSerializer());
objectMapper.registerModule(module);
......
......@@ -186,7 +186,7 @@ public class NetworkRemoteServiceImpl extends BaseRemoteServiceImpl implements N
Preconditions.checkNotNull(peeringDocument);
// http post /tx/process
HttpPost httpPost = new HttpPost(getPath(peer, URL_PEERING_PEERS));
HttpPost httpPost = new HttpPost(getPath(peer, URL_PEERING));
if (log.isDebugEnabled()) {
log.debug(String.format(
......
package org.duniter.core.client.util;
import org.duniter.core.client.model.bma.BlockchainBlock;
import org.duniter.core.exception.TechnicalException;
public class KnownBlocks {
private KnownBlocks() {
// helper class
}
public static BlockchainBlock getFirstBlock(String currencyId) {
BlockchainBlock result = new BlockchainBlock();
result.setNumber(0);
// G1 currency
switch (currencyId) {
case KnownCurrencies.G1 :
result.setCurrency("g1");
result.setHash("000003D02B95D3296A4F06DBAC51775C4336A4DC09D0E958DC40033BE7E20F3D");
result.setTime(1488987127L);
result.setMedianTime(1488987127L);
result.setIssuer("2ny7YAdmzReQxAayyJZsyVYwYhVyax2thKcGknmQy5nQ");
result.setSignature("49OD/8pj0bU0Lg6HB4p+5TOcRbgtj8Ubxmhen4IbOXM+g33V/I56GfF+QbD9U138Ek04E9o0lSjaDIVI/BrkCw==");
break;
case KnownCurrencies.G1_TEST :
result.setCurrency("g1-test");
result.setHash("0000DEFA598EA82BC8FF19BC56B49A686E63617DCC7304FAF7F0461FA34E0F9C");
result.setTime(1496842431L);
result.setMedianTime(1496842431L);
result.setIssuer("3dnbnYY9i2bHMQUGyFp5GVvJ2wBkVpus31cDJA5cfRpj");
result.setSignature("OQQJ8TVISMgpz8SmdVGHYAUQMDnHpXqeFal4+/q2hV37uyrpC8iF6d50Wgg2TMKhsB/9zelOXZgbuzutAOZ5AA==");
break;
default:
throw new TechnicalException(String.format("First block for currency %s not defined !", currencyId));
}
return result;
}
}
package org.duniter.core.client.util;
public interface KnownCurrencies {
String G1 = "g1";
String G1_TEST = "g1-test";
}
duniter4j.client.authentication=Http request error (unauthorized or forbidden).
duniter4j.client.core.connect=Could not connect to Duniter node [%s]
duniter4j.client.authentication=Http request error\: unauthorized or forbidden
duniter4j.client.core.connect=Http request error {%s}\: could not connect
duniter4j.client.core.emptyResponse=[%s] Empty Response
duniter4j.client.core.invalidResponse=[%s] Invalid response
duniter4j.client.core.invalidResponseContentType=[%s] Invalid response content-type\: expected [%s] but get [%s]
......
duniter4j.client.authentication=Echec de la requete (Accès interdit ou non autorisé).
duniter4j.client.core.connect=Echec de la connection au noeud Duniter [%s]
duniter4j.client.authentication=Echec de la requete\: accès interdit ou non autorisé).
duniter4j.client.core.connect=Echec de la requete {%s}\: connection impossible
duniter4j.client.core.emptyResponse=[%s] Réponse vide
duniter4j.client.core.invalidResponse=[%s] Réponse non valide
duniter4j.client.core.invalidResponseContentType=[%s] Type de réponse invalide\: attendu [%s] mais [%s] obtenu
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment