/* P2PPool.java * * Copyright (c) 2003, Benja Fallenstein * * This file is part of Storm. * * Storm is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Storm 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 Lesser General * Public License for more details. * * You should have received a copy of the GNU Lesser General * Public License along with Storm; if not, write to the Free * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * * */ /* * Written by Benja Fallenstein */ package org.nongnu.storm.impl.p2p; import org.nongnu.storm.*; import org.nongnu.storm.impl.*; import org.nongnu.storm.util.*; import java.io.*; import java.net.*; import java.util.*; /** A class that publishes a Storm pool through p2p and * makes the p2p network available as another pool. */ public class Peer { protected P2PPool pool; protected HTTPProxy server; public Peer(IndexedPool publishedPool, StormPool cachePool, P2PMap map) throws IOException { if(publishedPool == null) publishedPool = new TransientPool(Collections.EMPTY_SET); pool = new P2PPool(map, cachePool, publishedPool.getIndices().keySet()); server = new HTTPProxy(publishedPool, 37000+(int)(2000 * new java.util.Random().nextDouble())); for(Iterator i=publishedPool.getIds().block().iterator(); i.hasNext();) { BlockId id = (BlockId)i.next(); map.put(id.toString(), server.getURL()+id.toString()); } new Thread(server).start(); // XXX put indexing information into pool! } public IndexedPool getPool() { return pool; } public HTTPProxy getServer() { return server; } public static void main(String[] args) throws Exception { boolean gisp = false; String dir = args[0]; if(dir.equals("-gisp")) { dir = args[1]; gisp = true; } Set idx = new HashSet(); DirPool pub = new DirPool(new File(dir), idx); StormPool cache = new TransientPool(idx); P2PMap map; if(!gisp) map = new MockP2PMap(); else map = new org.nongnu.storm.modules.gispmap.GispP2PMap(57083, null); Peer p = new Peer(pub, cache, map); if(!gisp) new HTTPProxy(p.getPool(), 5555).run(); else while(true); } }