2 * Copyright (c) 2007-2008 Fabrizio Frioli, Michele Pedrolli
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 2 as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 * Please send your questions/suggestions to:
20 * {fabrizio.frioli, michele.pedrolli} at studenti dot unitn dot it
24 package example.bittorrent;
26 import peersim.core.*;
29 * This class is a {@link SimpleMsg} and represents the <tt>bitfield</tt>
32 public class BitfieldMsg extends SimpleMsg{
34 * The status of the file to transmit to neighbors nodes
39 * Defines the type of the Bitfield message. If <tt>isRequest</tt> is true, then
40 * the message is a request of subscription; otherwise the message is a response.
45 * <p>The ACK value used to implement <i>ack</i> and <i>nack</i> messages.</p>
46 * <p>It has value <tt>true</tt> if the message is a reponse and the sender has inserted
47 * the receiver in its own cache of neighbors.<br/>
48 * If for some reason (for instance the cache had already 80 peer inside at the moment of the
49 * request) it was not possible to insert the peer, the value is <tt>false</tt>.<br/>
50 * It has value <tt>false</tt> also if the message is a request and is sent when occours
51 * an unespected message.
53 * @see "The documentation to understand the 4 different types of Bitfield messages"
58 * The basic constructor of the Bitfield message.
59 * @param type The type of the message, according to {@link SimpleMsg}
60 * @param isRequest Defines if the message is a request or not
61 * @param ack Defines if the message type is an <i>ack</i> or a <i>nack</i>
62 * @param sender The sender node
63 * @param source The array containing the status of the file
64 * @param size The size of the array
66 public BitfieldMsg(int type, boolean isRequest, boolean ack, Node sender, int source[], int size){
68 super.sender = sender;
69 this.isRequest = isRequest;
71 this.array = new int[size];
72 for(int i=0; i<size;i++){ // it sends a copy
81 * Gets the array containing the status of the file.
82 * @return The status of the file
84 public int[] getArray(){