• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java SharedTorrent类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.turn.ttorrent.client.SharedTorrent的典型用法代码示例。如果您正苦于以下问题:Java SharedTorrent类的具体用法?Java SharedTorrent怎么用?Java SharedTorrent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SharedTorrent类属于com.turn.ttorrent.client包,在下文中一共展示了SharedTorrent类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: update

import com.turn.ttorrent.client.SharedTorrent; //导入依赖的package包/类
@Override
public void update(Observable observable, Object data) {
    Client client = (Client) observable;
    Client.ClientState state = (Client.ClientState) data;
    SharedTorrent st = client.getTorrent();

    long now = System.nanoTime();
    long downloaded = st.getDownloaded();

    torrentDownloadStatus.setEstTimeNano(DownloadStatus.computeEstTime(startTime, now, downloaded, st.getLeft() + st.getDownloaded()));
    torrentDownloadStatus.setSpeedNano((downloaded - lastDownloaded) / (double) (now - lastTime));
    torrentDownloadStatus.updateValues(client);

    if(st.isFinished() || canceled || state.equals(Client.ClientState.ERROR) || state.equals(Client.ClientState.DONE)) {
        finishDwonload();
        return;
    }

    statusUpdater.notifyDownloadStatusUpdaters(torrentDownloadStatus);

    lastDownloaded = downloaded;
    lastTime = now;

}
 
开发者ID:jhkst,项目名称:dlface,代码行数:25,代码来源:TorrentStateObserver.java


示例2: updateValues

import com.turn.ttorrent.client.SharedTorrent; //导入依赖的package包/类
public void updateValues(Client client) {
    SharedTorrent sharedTorrent = client.getTorrent();
    this.setName(sharedTorrent.getName() + " (" + sharedTorrent.getFilenames().size() + " file(s))");
    this.setTotalSize(sharedTorrent.getSize());
    this.setDownloadedSize(sharedTorrent.getDownloaded());
    this.setProgress(sharedTorrent.getCompletion());
    this.setState(String.valueOf(client.getState()));
    this.setComment(sharedTorrent.getComment());
    this.setPieceCount(sharedTorrent.getPieceCount());
    this.setCompletion(sharedTorrent.getCompletion());
    this.setUploaded(sharedTorrent.getUploaded());
    this.setMaxDownloadRate(sharedTorrent.getMaxDownloadRate());
    this.setMaxUploadRate(sharedTorrent.getMaxUploadRate());
    List<PeerDataTO> peers = client.getPeers().stream().map(PeerDataTO::new).collect(Collectors.toList());
    this.setPeers(peers);
    this.setPeersCount(client.getPeers().size());
    this.setTrackerCount(sharedTorrent.getTrackerCount());
    this.setInfoHash(sharedTorrent.getHexInfoHash());
    this.setFilenames(sharedTorrent.getFilenames());
    if (sharedTorrent.isInitialized()) {
        this.setCompletedPieces(Util.compressToUri(sharedTorrent.getCompletedPieces()));
        this.setAvailablePieces(Util.compressToUri(sharedTorrent.getAvailablePieces()));
        this.setRequestedPieces(Util.compressToUri(sharedTorrent.getRequestedPieces()));
    }
}
 
开发者ID:jhkst,项目名称:dlface,代码行数:26,代码来源:TorrentDownloadStatus.java


示例3: init

import com.turn.ttorrent.client.SharedTorrent; //导入依赖的package包/类
private void init() throws UnknownHostException, NoSuchAlgorithmException, IOException{
	this.setTitle(torrent.getName());
	Client torrentClient = new Client(InetAddress.getLocalHost(), 
			SharedTorrent.fromFile(torrent,folder));
	torrentClient.addObserver(this);
	this.getContentPane().setLayout(new BoxLayout(this.getContentPane(), BoxLayout.PAGE_AXIS));
	this.getContentPane().add(state);
	this.getContentPane().add(peers);
	this.getContentPane().add(dl);
	this.getContentPane().add(completion);
	this.setLocationRelativeTo(null);
	this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
	this.setSize(400, 122);
	this.setResizable(false);
	this.setVisible(true);
	torrentClient.download();
}
 
开发者ID:redSpoutnik,项目名称:AutoRename,代码行数:18,代码来源:TorrentDownloadManager.java


示例4: addTorrent

import com.turn.ttorrent.client.SharedTorrent; //导入依赖的package包/类
public TfsTorrent addTorrent(Torrent torrent) throws IOException {
  String infoHash = torrent.getHexInfoHash();
  if (lookup.containsKey(infoHash)) return lookup.get(infoHash);

  File f = new File(rootPath + infoHash + "/");
  f.mkdirs();
  TfsTorrent tfs = null;
  try {
    tfs = new TfsTorrent(new Client(address, new SharedTorrent(torrent, f)), infoHash);
  } catch (NoSuchAlgorithmException e) {
    throw new RuntimeException("Required Crypto algorithms not installed.");
  }
  tfs.client.addObserver(new Observer() {
    @Override
    public void update(Observable arg0, Object arg1) {
      onClientUpdate((Client) arg0, (ClientState) arg1);
    }
  });
  lookup.put(infoHash, tfs);
  tfs.client.share();
  return tfs;
}
 
开发者ID:cjmalloy,项目名称:torrent-fs,代码行数:23,代码来源:TfsClient.java


示例5: UDPTrackerClient

import com.turn.ttorrent.client.SharedTorrent; //导入依赖的package包/类
/**
 * 
 * @param torrent
 */
protected UDPTrackerClient(SharedTorrent torrent, Peer peer, URI tracker)
	throws UnknownHostException {
	super(torrent, peer, tracker);

	/**
	 * The UDP announce request protocol only supports IPv4
	 *
	 * @see http://bittorrent.org/beps/bep_0015.html#ipv6
	 */
	if (! (InetAddress.getByName(peer.getIp()) instanceof Inet4Address)) {
		throw new UnsupportedAddressTypeException();
	}

	this.address = new InetSocketAddress(
		tracker.getHost(),
		tracker.getPort());

	this.socket = null;
	this.random = new Random();
	this.connectionExpiration = null;
	this.stop = false;
}
 
开发者ID:DurandA,项目名称:bitworker,代码行数:27,代码来源:UDPTrackerClient.java


示例6: startSeeder

import com.turn.ttorrent.client.SharedTorrent; //导入依赖的package包/类
private Client startSeeder() throws IOException, NoSuchAlgorithmException {
    Torrent torrent = Torrent.load(new File(TORRENT_FILE));
    File destination = new File(CONTENT_DIRECTORY);
    InetAddress addr = InetAddress.getLocalHost();
    Client client = new Client(addr, new SharedTorrent(torrent, destination));
    client.share();
    return client;
}
 
开发者ID:philipphenkel,项目名称:ttorrent-android-service,代码行数:9,代码来源:TtorrentDownloaderTest.java


示例7: stopSeedingByPath

import com.turn.ttorrent.client.SharedTorrent; //导入依赖的package包/类
public void stopSeedingByPath(File file){
   final SharedTorrent torrentByName = myClient.getTorrentByFilePath(file);
   if (torrentByName != null) {
     LOG.info("Stopped seeding torrent by file: " + file.getAbsolutePath());
     myClient.removeTorrent(torrentByName);
   }
}
 
开发者ID:JetBrains,项目名称:teamcity-torrent-plugin,代码行数:8,代码来源:TeamcityTorrentClient.java


示例8: findSeedingTorrentFolder

import com.turn.ttorrent.client.SharedTorrent; //导入依赖的package包/类
public File findSeedingTorrentFolder(@NotNull TorrentHash torrent){
  for (SharedTorrent st : myClient.getTorrents()) {
    if (st.getHexInfoHash().equals(torrent.getHexInfoHash())){
      return st.getParentFile();
    }
  }
  return null;
}
 
开发者ID:JetBrains,项目名称:teamcity-torrent-plugin,代码行数:9,代码来源:TeamcityTorrentClient.java


示例9: createTrackerClient

import com.turn.ttorrent.client.SharedTorrent; //导入依赖的package包/类
/**
 * Create a {@link TrackerClient} annoucing to the given tracker address.
 *
 * @param torrent The torrent the tracker client will be announcing for.
 * @param peer The peer the tracker client will announce on behalf of.
 * @param tracker The tracker address as a {@link URI}.
 * @throws UnknownHostException If the tracker address is invalid.
 * @throws UnknownServiceException If the tracker protocol is not supported.
 */
private TrackerClient createTrackerClient(SharedTorrent torrent, Peer peer,
	URI tracker) throws UnknownHostException, UnknownServiceException {
	String scheme = tracker.getScheme();

	if ("http".equals(scheme) || "https".equals(scheme)) {
		return new HTTPTrackerClient(torrent, peer, tracker);
	} else if ("udp".equals(scheme)) {
		return new UDPTrackerClient(torrent, peer, tracker);
	}

	throw new UnknownServiceException(
		"Unsupported announce scheme: " + scheme + "!");
}
 
开发者ID:DurandA,项目名称:bitworker,代码行数:23,代码来源:Announce.java


示例10: PeerExchange

import com.turn.ttorrent.client.SharedTorrent; //导入依赖的package包/类
/**
 * Initialize and start a new peer exchange.
 *
 * @param peer The remote peer to communicate with.
 * @param torrent The torrent we're exchanging on with the peer.
 * @param channel A channel on the connected socket to the peer.
 */
public PeerExchange(SharingPeer peer, SharedTorrent torrent,
		SocketChannel channel) throws SocketException {
	this.peer = peer;
	this.torrent = torrent;
	this.channel = channel;

	this.listeners = new HashSet<MessageListener>();
	this.sendQueue = new LinkedBlockingQueue<PeerMessage>();

	if (!this.peer.hasPeerId()) {
		throw new IllegalStateException("Peer does not have a " +
				"peer ID. Was the handshake made properly?");
	}

	this.in = new IncomingThread();
	this.in.setName("bt-peer(" +
		this.peer.getShortHexPeerId() + ")-recv");

	this.out = new OutgoingThread();
	this.out.setName("bt-peer(" +
		this.peer.getShortHexPeerId() + ")-send");
	this.out.setDaemon(true);

	// Automatically start the exchange activity loops
	this.stop = false;
	this.in.start();
	this.out.start();

	logger.debug("Started peer exchange with {} for {}.",
		this.peer, this.torrent);

	// If we have pieces, start by sending a BITFIELD message to the peer.
	BitSet pieces = this.torrent.getCompletedPieces();
	if (pieces.cardinality() > 0) {
		this.send(PeerMessage.BitfieldMessage.craft(pieces));
	}
}
 
开发者ID:DurandA,项目名称:bitworker,代码行数:45,代码来源:PeerExchange.java


示例11: SharingPeer

import com.turn.ttorrent.client.SharedTorrent; //导入依赖的package包/类
/**
 * Create a new sharing peer on a given torrent.
 *
 * @param ip The peer's IP address.
 * @param port The peer's port.
 * @param peerId The byte-encoded peer ID.
 * @param torrent The torrent this peer exchanges with us on.
 */
public SharingPeer(String ip, int port, ByteBuffer peerId,
		SharedTorrent torrent) {
	super(ip, port, peerId);

	this.torrent = torrent;
	this.listeners = new HashSet<PeerActivityListener>();
	this.availablePieces = new BitSet(this.torrent.getPieceCount());

	this.requestsLock = new Object();
	this.exchangeLock = new Object();

	this.reset();
	this.requestedPiece = null;
}
 
开发者ID:DurandA,项目名称:bitworker,代码行数:23,代码来源:SharingPeer.java


示例12: validate

import com.turn.ttorrent.client.SharedTorrent; //导入依赖的package包/类
@Override
public HaveMessage validate(SharedTorrent torrent)
	throws MessageValidationException {
	if (this.piece >= 0 && this.piece < torrent.getPieceCount()) {
		return this;
	}

	throw new MessageValidationException(this);
}
 
开发者ID:DurandA,项目名称:bitworker,代码行数:10,代码来源:PeerMessage.java


示例13: parse

import com.turn.ttorrent.client.SharedTorrent; //导入依赖的package包/类
public static BitfieldMessage parse(ByteBuffer buffer,
		SharedTorrent torrent) throws MessageValidationException {
	BitSet bitfield = new BitSet(buffer.remaining()*8);
	for (int i=0; i < buffer.remaining()*8; i++) {
		if ((buffer.get(i/8) & (1 << (7 -(i % 8)))) > 0) {
			bitfield.set(i);
		}
	}

	return new BitfieldMessage(buffer, bitfield)
		.validate(torrent);
}
 
开发者ID:DurandA,项目名称:bitworker,代码行数:13,代码来源:PeerMessage.java


示例14: getSharedTorrents

import com.turn.ttorrent.client.SharedTorrent; //导入依赖的package包/类
@NotNull
public Collection<SharedTorrent> getSharedTorrents() {
  return myTorrentsSeeder.getSharedTorrents();
}
 
开发者ID:JetBrains,项目名称:teamcity-torrent-plugin,代码行数:5,代码来源:AgentTorrentsSeeder.java


示例15: getSharedTorrents

import com.turn.ttorrent.client.SharedTorrent; //导入依赖的package包/类
public Collection<SharedTorrent> getSharedTorrents() {
  return myTorrentsSeeder.getSharedTorrents();
}
 
开发者ID:JetBrains,项目名称:teamcity-torrent-plugin,代码行数:4,代码来源:ServerTorrentsDirectorySeeder.java


示例16: getSharedTorrents

import com.turn.ttorrent.client.SharedTorrent; //导入依赖的package包/类
@NotNull
public Collection<SharedTorrent> getSharedTorrents(){
  return myClient.getSharedTorrents();
}
 
开发者ID:JetBrains,项目名称:teamcity-torrent-plugin,代码行数:5,代码来源:TorrentsSeeder.java


示例17: isSeedingByPath

import com.turn.ttorrent.client.SharedTorrent; //导入依赖的package包/类
public boolean isSeedingByPath(File file){
  final SharedTorrent torrentByName = myClient.getTorrentByFilePath(file);
  return torrentByName != null;
}
 
开发者ID:JetBrains,项目名称:teamcity-torrent-plugin,代码行数:5,代码来源:TeamcityTorrentClient.java


示例18: getSharedTorrents

import com.turn.ttorrent.client.SharedTorrent; //导入依赖的package包/类
public Collection<SharedTorrent> getSharedTorrents(){
  return myClient.getTorrents();
}
 
开发者ID:JetBrains,项目名称:teamcity-torrent-plugin,代码行数:4,代码来源:TeamcityTorrentClient.java


示例19: Announce

import com.turn.ttorrent.client.SharedTorrent; //导入依赖的package包/类
/**
 * Initialize the base announce class members for the announcer.
 *
 * @param torrent The torrent we're announcing about.
 * @param peer Our peer specification.
 */
public Announce(SharedTorrent torrent, Peer peer) {
	this.peer = peer;
	this.clients = new ArrayList<List<TrackerClient>>();
	this.allClients = new HashSet<TrackerClient>();

	/**
	 * Build the tiered structure of tracker clients mapping to the
	 * trackers of the torrent.
	 */
	for (List<URI> tier : torrent.getAnnounceList()) {
		ArrayList<TrackerClient> tierClients = new ArrayList<TrackerClient>();
		for (URI tracker : tier) {
			try {
				TrackerClient client = this.createTrackerClient(torrent,
					peer, tracker);

				tierClients.add(client);
				this.allClients.add(client);
			} catch (Exception e) {
				logger.warn("Will not announce on {}: {}!",
					tracker,
					e.getMessage() != null
						? e.getMessage()
						: e.getClass().getSimpleName());
			}
		}

		// Shuffle the list of tracker clients once on creation.
		Collections.shuffle(tierClients);

		// Tier is guaranteed to be non-empty by
		// Torrent#parseAnnounceInformation(), so we can add it safely.
		clients.add(tierClients);
	}

	this.thread = null;
	this.currentTier = 0;
	this.currentClient = 0;

	logger.info("Initialized announce sub-system with {} trackers on {}.",
		new Object[] { torrent.getTrackerCount(), torrent });
}
 
开发者ID:DurandA,项目名称:bitworker,代码行数:49,代码来源:Announce.java


示例20: TrackerClient

import com.turn.ttorrent.client.SharedTorrent; //导入依赖的package包/类
public TrackerClient(SharedTorrent torrent, Peer peer, URI tracker) {
	this.listeners = new HashSet<AnnounceResponseListener>();
	this.torrent = torrent;
	this.peer = peer;
	this.tracker = tracker;
}
 
开发者ID:DurandA,项目名称:bitworker,代码行数:7,代码来源:TrackerClient.java



注:本文中的com.turn.ttorrent.client.SharedTorrent类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java OnStopEvent类代码示例发布时间:2022-05-23
下一篇:
Java MulExpr类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap