⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ringcertificate.java

📁 pastry的java实现的2.0b版
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*************************************************************************"FreePastry" Peer-to-Peer Application Development Substrate Copyright 2002, Rice University. All rights reserved.Redistribution and use in source and binary forms, with or withoutmodification, are permitted provided that the following conditions aremet:- Redistributions of source code must retain the above copyrightnotice, this list of conditions and the following disclaimer.- Redistributions in binary form must reproduce the above copyrightnotice, this list of conditions and the following disclaimer in thedocumentation and/or other materials provided with the distribution.- Neither  the name  of Rice  University (RICE) nor  the names  of itscontributors may be  used to endorse or promote  products derived fromthis software without specific prior written permission.This software is provided by RICE and the contributors on an "as is"basis, without any representations or warranties of any kind, expressor implied including, but not limited to, representations orwarranties of non-infringement, merchantability or fitness for aparticular purpose. In no event shall RICE or contributors be liablefor any direct, indirect, incidental, special, exemplary, orconsequential damages (including, but not limited to, procurement ofsubstitute goods or services; loss of use, data, or profits; orbusiness interruption) however caused and on any theory of liability,whether in contract, strict liability, or tort (including negligenceor otherwise) arising in any way out of the use of this software, evenif advised of the possibility of such damage.********************************************************************************/package rice.p2p.multiring;import java.io.*;import java.net.*;import java.security.*;import java.util.*;import java.util.zip.*;import rice.environment.Environment;import rice.p2p.commonapi.*;import rice.p2p.multiring.*;import rice.p2p.util.*;import rice.pastry.commonapi.*;import rice.pastry.dist.*;/** * @(#) RingCertificate.java This class represents a certificate for a specific * ring attached, which contains informtation about the ring, such as * bootstraps, etc... * * @version $Id: RingCertificate.java 2828 2005-12-02 17:50:01Z jstewart $ * @author Alan Mislove */public class RingCertificate implements Serializable {  // the name of this ring  /**   * DESCRIBE THE FIELD   */  protected String name;  // the Id of this ring  /**   * DESCRIBE THE FIELD   */  protected Id id;  // the protocol of this ring  /**   * DESCRIBE THE FIELD   */  protected Integer protocol;  // the list of bootstrap nodes for this ring  /**   * DESCRIBE THE FIELD   */  protected InetSocketAddress[] bootstraps;  // the preferred port for this ring  /**   * DESCRIBE THE FIELD   */  protected Integer port;  // the logserver for this ring  /**   * DESCRIBE THE FIELD   */  protected InetSocketAddress logServer;  // the key for the ring, used in visualization and log uploading  /**   * DESCRIBE THE FIELD   */  protected PublicKey key;  // the version number of this certificate  /**   * DESCRIBE THE FIELD   */  protected Long version;  // the signature of the above info  /**   * DESCRIBE THE FIELD   */  protected byte[] signature;  // serialver  private final static long serialVersionUID = 5915358246762577456L;  // the static map of all RingCertificates available (id -> cert)  /**   * DESCRIBE THE FIELD   */  protected static HashMap CERTIFICATES = new HashMap();  /**   * Builds a new RingCertificate given the appropriate info   *   * @param name DESCRIBE THE PARAMETER   * @param id DESCRIBE THE PARAMETER   * @param protocol DESCRIBE THE PARAMETER   * @param bootstraps DESCRIBE THE PARAMETER   * @param port DESCRIBE THE PARAMETER   * @param key DESCRIBE THE PARAMETER   * @param logServer DESCRIBE THE PARAMETER   */  public RingCertificate(String name, Id id, int protocol, InetSocketAddress[] bootstraps, int port, PublicKey key, InetSocketAddress logServer) {    this.name = name;    this.id = id;    this.bootstraps = bootstraps;    this.port = new Integer(port);    this.key = key;    this.logServer = logServer;    this.version = new Long(System.currentTimeMillis());    this.protocol = new Integer(protocol);  }  /**   * Returns the name of this ring   *   * @return The name   */  public String getName() {    return name;  }  /**   * Returns the id of this ring   *   * @return The id   */  public Id getId() {    return id;  }  /**   * Returns the protcol of this ring   *   * @return The protocol   */  public int getProtocol() {    return protocol.intValue();  }  /**   * Returns the version of this ring cert   *   * @return The version   */  public long getVersion() {    return version.longValue();  }  /**   * Returns the bootstraps of this ring   *   * @return The bootstraps   */  public InetSocketAddress[] getBootstraps() {    return bootstraps;  }  /**   * Returns the preferred port of this ring   *   * @return The preferred port   */  public int getPort() {    return port.intValue();  }  /**   * Returns the public key which is used to authenticate   *   * @return The public key   */  public PublicKey getKey() {    return key;  }  /**   * Returns the log server of this ring   *   * @return The log server   */  public InetSocketAddress getLogServer() {    return logServer;  }  /**   * Internal method which returns the to-be signed data   *   * @return The data   */  private Object getIdentifier() {    return new Object[]{name, id, bootstraps, port, key, logServer, version, protocol};  }  /**   * Refreshes all of the InetAddresses based on their name, not IP address. In   * other words, it fixes InetAddresses that are stale from storage. It reads   * the "name" of the InetAddress, and then builds a new InetAddress with this   * name which should do a proper dns lookup.   */  private void refresh() {    logServer = refreshAddress(logServer);  }  /**   * Helper function for refresh(). Returns an identical InetSocketAddress   * unless the ip address in address is stale. Then it returns the current one   * based on a dns lookup.   *   * @param address   * @return   */  private InetSocketAddress refreshAddress(InetSocketAddress address) {    return new InetSocketAddress(address.getAddress().getHostName(), address.getPort());  }  /**   * Signs this RingCertificate, given the private key to sign with   *   * @param priv DESCRIBE THE PARAMETER   * @priv The private key to sign with   */  private void sign(PrivateKey priv) {    if (signature != null) {      throw new IllegalArgumentException("Attempt to sign an already-signed RingCertificate!");    }    try {      signature = SecurityUtils.sign(SecurityUtils.serialize(getIdentifier()), priv);    } catch (IOException e) {      throw new RuntimeException(e);    }  }  /**   * Verifies this RingCertificate, given the public key to verify with   *   * @param pub DESCRIBE THE PARAMETER   * @return DESCRIBE THE RETURN VALUE   * @pub The public key to verify with   */  private boolean verify(PublicKey pub) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -