Changeset 5490de1 for router


Ignore:
Timestamp:
Apr 8, 2019 4:12:14 PM (15 months ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
cde5353
Parents:
488e89a
Message:

Router: Replace GarlicConfig? setters with constructor args

Location:
router/java
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/message/GarlicConfig.java

    r488e89a r5490de1  
    2828    private RouterInfo _recipient;
    2929    private PublicKey _recipientPublicKey;
    30     private Certificate _cert;
    31     private long _id;
    32     private long _expiration;
     30    private final Certificate _cert;
     31    private final long _id;
     32    private final long _expiration;
    3333    private final List<GarlicConfig> _cloveConfigs;
    34     private DeliveryInstructions _instructions;
     34    private final DeliveryInstructions _instructions;
    3535    // unused
    3636    //private boolean _requestAck;
     
    4242    //private long _replyBlockExpiration;
    4343   
    44     public GarlicConfig() {
    45         this(new ArrayList<GarlicConfig>(4));
     44    public GarlicConfig(Certificate cert, long id, long expiration, DeliveryInstructions di) {
     45        this(new ArrayList<GarlicConfig>(4), cert, id, expiration, di);
    4646    }
    4747
    48     protected GarlicConfig(List<GarlicConfig> cloveConfigs) {
    49         _id = -1;
    50         _expiration = -1;
     48    protected GarlicConfig(List<GarlicConfig> cloveConfigs, Certificate cert, long id,
     49                           long expiration, DeliveryInstructions di) {
     50        _cert = cert;
     51        _id = id;
     52        _expiration = expiration;
    5153        _cloveConfigs = cloveConfigs;
     54        _instructions = di;
    5255        //_replyBlockMessageId = -1;
    5356        //_replyBlockExpiration = -1;
     
    8083     *
    8184     */
    82     public void setCertificate(Certificate cert) { _cert = cert; }
    8385    public Certificate getCertificate() { return _cert; }
    8486   
     
    8789     *
    8890     */
    89     public void setId(long id) { _id = id; }
    9091    public long getId() { return _id; }
    9192   
     
    9495     *
    9596     */
    96     public void setExpiration(long expiration) { _expiration = expiration; }
    9797    public long getExpiration() { return _expiration; }
    9898 
     
    101101     *
    102102     */
    103     public void setDeliveryInstructions(DeliveryInstructions instructions) { _instructions = instructions; }
    104103    public DeliveryInstructions getDeliveryInstructions() { return _instructions; }
    105104   
  • router/java/src/net/i2p/router/message/OutboundClientMessageJobHelper.java

    r488e89a r5490de1  
    147147        if (replyToken >= 0 && log.shouldLog(Log.DEBUG))
    148148            log.debug("Reply token: " + replyToken);
    149         GarlicConfig config = new GarlicConfig();
     149        GarlicConfig config = new GarlicConfig(Certificate.NULL_CERT,
     150                                               ctx.random().nextLong(I2NPMessage.MAX_ID_VALUE),
     151                                               expiration, DeliveryInstructions.LOCAL);
    150152       
    151153        if (requireAck) {
     
    168170        config.addClove(dataClove);
    169171
    170         config.setCertificate(Certificate.NULL_CERT);
    171         config.setDeliveryInstructions(DeliveryInstructions.LOCAL);
    172         config.setId(ctx.random().nextLong(I2NPMessage.MAX_ID_VALUE));
    173         config.setExpiration(expiration); // +2*Router.CLOCK_FUDGE_FACTOR);
    174172        config.setRecipientPublicKey(recipientPK);
    175173       
     
    214212        //ackInstructions.setEncrypted(false);
    215213       
    216         PayloadGarlicConfig ackClove = new PayloadGarlicConfig();
    217         ackClove.setCertificate(Certificate.NULL_CERT);
    218         ackClove.setDeliveryInstructions(ackInstructions);
    219         ackClove.setExpiration(expiration);
    220         ackClove.setId(ctx.random().nextLong(I2NPMessage.MAX_ID_VALUE));
    221214        DeliveryStatusMessage dsm = buildDSM(ctx, replyToken);
    222215        GarlicMessage msg = wrapDSM(ctx, skm, dsm);
     
    226219            return null;
    227220        }
    228         ackClove.setPayload(msg);
     221        PayloadGarlicConfig ackClove = new PayloadGarlicConfig(Certificate.NULL_CERT,
     222                                                               ctx.random().nextLong(I2NPMessage.MAX_ID_VALUE),
     223                                                               expiration, ackInstructions, msg);
    229224        // this does nothing, the clove is not separately encrypted
    230225        //ackClove.setRecipient(ctx.router().getRouterInfo());
     
    284279        //instructions.setEncrypted(false);
    285280       
    286         PayloadGarlicConfig clove = new PayloadGarlicConfig();
    287         clove.setCertificate(Certificate.NULL_CERT);
    288         clove.setDeliveryInstructions(instructions);
    289         clove.setExpiration(expiration);
    290         clove.setId(ctx.random().nextLong(I2NPMessage.MAX_ID_VALUE));
    291281        DataMessage msg = new DataMessage(ctx);
    292282        msg.setData(data.getEncryptedData());
    293         clove.setPayload(msg);
     283        PayloadGarlicConfig clove = new PayloadGarlicConfig(Certificate.NULL_CERT,
     284                                                            ctx.random().nextLong(I2NPMessage.MAX_ID_VALUE),
     285                                                            expiration, instructions, msg);
    294286        // defaults
    295287        //clove.setRecipientPublicKey(null);
     
    304296     */
    305297    private static PayloadGarlicConfig buildLeaseSetClove(RouterContext ctx, long expiration, LeaseSet replyLeaseSet) {
    306         PayloadGarlicConfig clove = new PayloadGarlicConfig();
    307         clove.setCertificate(Certificate.NULL_CERT);
    308         clove.setDeliveryInstructions(DeliveryInstructions.LOCAL);
    309         clove.setExpiration(expiration);
    310         clove.setId(ctx.random().nextLong(I2NPMessage.MAX_ID_VALUE));
    311298        DatabaseStoreMessage msg = new DatabaseStoreMessage(ctx);
    312299        msg.setEntry(replyLeaseSet);
    313300        msg.setMessageExpiration(expiration);
    314         clove.setPayload(msg);
     301        PayloadGarlicConfig clove = new PayloadGarlicConfig(Certificate.NULL_CERT,
     302                                                            ctx.random().nextLong(I2NPMessage.MAX_ID_VALUE),
     303                                                            expiration, DeliveryInstructions.LOCAL, msg);
    315304        // defaults
    316305        //clove.setRecipientPublicKey(null);
  • router/java/src/net/i2p/router/message/OutboundClientMessageOneShotJob.java

    r488e89a r5490de1  
    904904     */
    905905    private PayloadGarlicConfig buildClove() {
    906         PayloadGarlicConfig clove = new PayloadGarlicConfig();
    907        
    908906        DeliveryInstructions instructions = new DeliveryInstructions();
    909907        instructions.setDeliveryMode(DeliveryInstructions.DELIVERY_MODE_DESTINATION);
     
    914912        //instructions.setDelaySeconds(0);
    915913        //instructions.setEncrypted(false);
    916        
    917         clove.setCertificate(Certificate.NULL_CERT);
    918         clove.setDeliveryInstructions(instructions);
    919         clove.setExpiration(OVERALL_TIMEOUT_MS_DEFAULT+getContext().clock().now());
    920         clove.setId(getContext().random().nextLong(I2NPMessage.MAX_ID_VALUE));
    921914       
    922915        DataMessage msg = new DataMessage(getContext());
     
    928921            return null;
    929922        msg.setData(d);
    930         msg.setMessageExpiration(clove.getExpiration());
    931        
    932         clove.setPayload(msg);
     923        long expires = OVERALL_TIMEOUT_MS_DEFAULT + getContext().clock().now();
     924        msg.setMessageExpiration(expires);
     925        PayloadGarlicConfig clove = new PayloadGarlicConfig(Certificate.NULL_CERT,
     926                                                            getContext().random().nextLong(I2NPMessage.MAX_ID_VALUE),
     927                                                            expires,
     928                                                            instructions, msg);
     929       
    933930        // defaults
    934931        //clove.setRecipientPublicKey(null);
  • router/java/src/net/i2p/router/message/PayloadGarlicConfig.java

    r488e89a r5490de1  
    99 */
    1010
     11import net.i2p.data.Certificate;
     12import net.i2p.data.i2np.DeliveryInstructions;
    1113import net.i2p.data.i2np.I2NPMessage;
    1214
     
    1820 */
    1921public class PayloadGarlicConfig extends GarlicConfig {
    20     private I2NPMessage _payload;
     22    private final I2NPMessage _payload;
    2123
    22     public PayloadGarlicConfig() {
    23         super(null);
     24    public PayloadGarlicConfig(Certificate cert, long id, long expiration,
     25                               DeliveryInstructions di, I2NPMessage message) {
     26        super(null, cert, id, expiration, di);
     27        _payload = message;
    2428    }
    2529   
     
    2832     * in this block
    2933     */
    30     public void setPayload(I2NPMessage message) {
    31         _payload = message;
    32     }
    33 
    3434    public I2NPMessage getPayload() { return _payload; }
    3535 
  • router/java/src/net/i2p/router/networkdb/kademlia/MessageWrapper.java

    r488e89a r5490de1  
    4444     */
    4545    static WrappedMessage wrap(RouterContext ctx, I2NPMessage m, Hash from, RouterInfo to) {
    46         PayloadGarlicConfig payload = new PayloadGarlicConfig();
    47         payload.setCertificate(Certificate.NULL_CERT);
    48         payload.setId(ctx.random().nextLong(I2NPMessage.MAX_ID_VALUE));
    49         payload.setPayload(m);
     46        PayloadGarlicConfig payload = new PayloadGarlicConfig(Certificate.NULL_CERT,
     47                                                              ctx.random().nextLong(I2NPMessage.MAX_ID_VALUE),
     48                                                              m.getMessageExpiration(),
     49                                                              DeliveryInstructions.LOCAL, m);
    5050        payload.setRecipient(to);
    51         payload.setDeliveryInstructions(DeliveryInstructions.LOCAL);
    52         payload.setExpiration(m.getMessageExpiration());
    5351
    5452        SessionKeyManager skm;
     
    125123     */
    126124    static GarlicMessage wrap(RouterContext ctx, I2NPMessage m, RouterInfo to) {
    127         PayloadGarlicConfig payload = new PayloadGarlicConfig();
    128         payload.setCertificate(Certificate.NULL_CERT);
    129         payload.setId(ctx.random().nextLong(I2NPMessage.MAX_ID_VALUE));
    130         payload.setPayload(m);
     125        PayloadGarlicConfig payload = new PayloadGarlicConfig(Certificate.NULL_CERT,
     126                                                              ctx.random().nextLong(I2NPMessage.MAX_ID_VALUE),
     127                                                              m.getMessageExpiration(),
     128                                                              DeliveryInstructions.LOCAL, m);
    131129        payload.setRecipient(to);
    132         payload.setDeliveryInstructions(DeliveryInstructions.LOCAL);
    133         payload.setExpiration(m.getMessageExpiration());
    134130
    135131        SessionKey sentKey = ctx.keyGenerator().generateSessionKey();
     
    225221     */
    226222    public static GarlicMessage wrap(RouterContext ctx, I2NPMessage m, SessionKey encryptKey, SessionTag encryptTag) {
    227         PayloadGarlicConfig payload = new PayloadGarlicConfig();
    228         payload.setCertificate(Certificate.NULL_CERT);
    229         payload.setId(ctx.random().nextLong(I2NPMessage.MAX_ID_VALUE));
    230         payload.setPayload(m);
    231         payload.setDeliveryInstructions(DeliveryInstructions.LOCAL);
    232         payload.setExpiration(m.getMessageExpiration());
     223        PayloadGarlicConfig payload = new PayloadGarlicConfig(Certificate.NULL_CERT,
     224                                                              ctx.random().nextLong(I2NPMessage.MAX_ID_VALUE),
     225                                                              m.getMessageExpiration(),
     226                                                              DeliveryInstructions.LOCAL, m);
    233227
    234228        GarlicMessage msg = GarlicMessageBuilder.buildMessage(ctx, payload, null, null,
  • router/java/src/net/i2p/router/tunnel/pool/TestJob.java

    r488e89a r5490de1  
    116116        // remembering that key+tag so that we can decrypt it later.  this means we can do the
    117117        // garlic encryption without any ElGamal (yay)
    118         PayloadGarlicConfig payload = new PayloadGarlicConfig();
    119         payload.setCertificate(Certificate.NULL_CERT);
    120         payload.setId(getContext().random().nextLong(I2NPMessage.MAX_ID_VALUE));
    121         payload.setPayload(m);
     118        PayloadGarlicConfig payload = new PayloadGarlicConfig(Certificate.NULL_CERT,
     119                                                              getContext().random().nextLong(I2NPMessage.MAX_ID_VALUE),
     120                                                              m.getMessageExpiration(),
     121                                                              DeliveryInstructions.LOCAL, m);
    122122        payload.setRecipient(getContext().router().getRouterInfo());
    123         payload.setDeliveryInstructions(DeliveryInstructions.LOCAL);
    124         payload.setExpiration(m.getMessageExpiration());
    125123
    126124        SessionKey encryptKey = getContext().keyGenerator().generateSessionKey();
  • router/java/test/junit/net/i2p/router/message/BuildTestMessageJob.java

    r488e89a r5490de1  
    104104        if (_log.shouldLog(Log.INFO))
    105105            _log.info("Test message key: " + _testMessageKey);
    106         GarlicConfig config = new GarlicConfig();
    107        
    108         PayloadGarlicConfig ackClove = buildAckClove();
    109         config.addClove(ackClove);
    110        
     106
    111107        DeliveryInstructions instructions = new DeliveryInstructions();
    112108        instructions.setDeliveryMode(DeliveryInstructions.DELIVERY_MODE_ROUTER);
     
    114110        instructions.setTunnelId(null);
    115111       
    116         config.setCertificate(new Certificate(Certificate.CERTIFICATE_TYPE_NULL, null));
    117         config.setDeliveryInstructions(instructions);
    118         config.setId(getContext().random().nextLong(I2NPMessage.MAX_ID_VALUE));
    119         config.setExpiration(_timeoutMs+getContext().clock().now()+2*Router.CLOCK_FUDGE_FACTOR);
     112        GarlicConfig config = new GarlicConfig(new Certificate(Certificate.CERTIFICATE_TYPE_NULL, null),
     113                                               getContext().random().nextLong(I2NPMessage.MAX_ID_VALUE),
     114                                               _timeoutMs+getContext().clock().now()+2*Router.CLOCK_FUDGE_FACTOR,
     115                                               instructions);
     116       
     117        PayloadGarlicConfig ackClove = buildAckClove();
     118        config.addClove(ackClove);
     119       
    120120        config.setRecipient(_target);
    121121       
     
    127127     */
    128128    private PayloadGarlicConfig buildAckClove() {
    129         PayloadGarlicConfig ackClove = new PayloadGarlicConfig();
    130129       
    131130        DeliveryInstructions ackInstructions = new DeliveryInstructions();
     
    139138            _log.debug("Delivery status message key: " + _testMessageKey + " arrival: " + msg.getArrival());
    140139       
    141         ackClove.setCertificate(new Certificate(Certificate.CERTIFICATE_TYPE_NULL, null));
    142         ackClove.setDeliveryInstructions(ackInstructions);
    143         ackClove.setExpiration(_timeoutMs+getContext().clock().now());
    144         ackClove.setId(getContext().random().nextLong(I2NPMessage.MAX_ID_VALUE));
    145         ackClove.setPayload(msg);
     140        PayloadGarlicConfig ackClove = new PayloadGarlicConfig(new Certificate(Certificate.CERTIFICATE_TYPE_NULL, null),
     141                                                               getContext().random().nextLong(I2NPMessage.MAX_ID_VALUE),
     142                                                               _timeoutMs+getContext().clock().now(),
     143                                                               ackInstructions,
     144                                                               msg);
    146145        ackClove.setRecipient(_target);
    147146       
Note: See TracChangeset for help on using the changeset viewer.