2
* Created on Apr 30, 2004
3
* Created by Alon Rohter
4
* Copyright (C) 2004, 2005, 2006 Aelitis, All Rights Reserved.
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
* AELITIS, SAS au capital de 46,603.30 euros
19
* 8 Allee Lenotre, La Grille Royale, 78600 Le Mesnil le Roi, France.
23
package com.aelitis.azureus.core.peermanager.messaging.azureus.session;
27
import org.gudy.azureus2.core3.util.*;
29
import com.aelitis.azureus.core.peermanager.messaging.*;
30
import com.aelitis.azureus.core.peermanager.messaging.azureus.AZMessage;
35
* Sent to initiate a torrent session.
37
public class AZSessionSyn implements AZMessage {
38
private DirectByteBuffer buffer = null;
39
private String description = null;
41
private final byte[] infohash;
42
private final int session_id;
43
private final Map session_info;
45
public AZSessionSyn( byte[] infohash, int local_session_id, Map session_info ) {
46
this.session_id = local_session_id;
47
this.infohash = infohash;
48
this.session_info = session_info;
52
public byte[] getInfoHash() { return infohash; }
53
public int getSessionID(){ return session_id; }
54
public Map getSessionInfo() { return session_info; }
58
public String getID() { return AZMessage.ID_AZ_SESSION_SYN; }
59
public byte[] getIDBytes() { return AZMessage.ID_AZ_SESSION_SYN_BYTES; }
61
public String getFeatureID() { throw new RuntimeException( "not implemented" ); } //TODO
62
public int getFeatureSubID() { throw new RuntimeException( "not implemented" ); } //TODO
64
public int getType() { return Message.TYPE_PROTOCOL_PAYLOAD; }
67
public String getDescription() {
68
if( description == null ) {
69
description = getID()+ " session id " +session_id+ " for infohash " +ByteFormatter.nicePrint( infohash, true );
75
public DirectByteBuffer[] getData() {
76
if( buffer == null ) {
77
Map payload_map = new HashMap();
79
payload_map.put( "session_id", new Long(session_id) );
80
payload_map.put( "infohash", infohash );
81
payload_map.put( "info", session_info );
83
buffer = MessagingUtil.convertPayloadToBencodedByteStream( payload_map, DirectByteBuffer.AL_MSG );
86
return new DirectByteBuffer[]{ buffer };
90
public Message deserialize( DirectByteBuffer data ) throws MessageException {
91
Map root = MessagingUtil.convertBencodedByteStreamToPayload( data, 20, getID() );
93
Long id = (Long)root.get( "session_id" );
94
if( id == null ) throw new MessageException( "id == null" );
95
int sid = id.intValue();
97
byte[] hash = (byte[])root.get( "infohash" );
98
if( hash == null ) throw new MessageException( "hash == null" );
99
if( hash.length != 20 ) throw new MessageException( "hash.length != 20: " +hash.length );
101
Map info = (Map)root.get( "info" );
103
return new AZSessionSyn( hash, sid, info );
107
public void destroy() {
108
if( buffer != null ) buffer.returnToPool();
2
* Created on Apr 30, 2004
3
* Created by Alon Rohter
4
* Copyright (C) 2004, 2005, 2006 Aelitis, All Rights Reserved.
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
* AELITIS, SAS au capital de 46,603.30 euros
19
* 8 Allee Lenotre, La Grille Royale, 78600 Le Mesnil le Roi, France.
23
package com.aelitis.azureus.core.peermanager.messaging.azureus.session;
27
import org.gudy.azureus2.core3.util.*;
29
import com.aelitis.azureus.core.peermanager.messaging.*;
30
import com.aelitis.azureus.core.peermanager.messaging.azureus.AZMessage;
35
* Sent to initiate a torrent session.
37
public class AZSessionSyn implements AZMessage {
38
private final byte version;
39
private DirectByteBuffer buffer = null;
40
private String description = null;
42
private final byte[] infohash;
43
private final int session_id;
44
private final Map session_info;
46
public AZSessionSyn( byte[] infohash, int local_session_id, Map session_info, byte version ) {
47
this.session_id = local_session_id;
48
this.infohash = infohash;
49
this.session_info = session_info;
50
this.version = version;
54
public byte[] getInfoHash() { return infohash; }
55
public int getSessionID(){ return session_id; }
56
public Map getSessionInfo() { return session_info; }
60
public String getID() { return AZMessage.ID_AZ_SESSION_SYN; }
61
public byte[] getIDBytes() { return AZMessage.ID_AZ_SESSION_SYN_BYTES; }
63
public String getFeatureID() { throw new RuntimeException( "not implemented" ); } //TODO
64
public int getFeatureSubID() { throw new RuntimeException( "not implemented" ); } //TODO
66
public int getType() { return Message.TYPE_PROTOCOL_PAYLOAD; }
68
public byte getVersion() { return version; };
70
public String getDescription() {
71
if( description == null ) {
72
description = getID()+ " session id " +session_id+ " for infohash " +ByteFormatter.nicePrint( infohash, true );
78
public DirectByteBuffer[] getData() {
79
if( buffer == null ) {
80
Map payload_map = new HashMap();
82
payload_map.put( "session_id", new Long(session_id) );
83
payload_map.put( "infohash", infohash );
84
payload_map.put( "info", session_info );
86
buffer = MessagingUtil.convertPayloadToBencodedByteStream( payload_map, DirectByteBuffer.AL_MSG );
89
return new DirectByteBuffer[]{ buffer };
93
public Message deserialize( DirectByteBuffer data, byte version ) throws MessageException {
94
Map root = MessagingUtil.convertBencodedByteStreamToPayload( data, 20, getID() );
96
Long id = (Long)root.get( "session_id" );
97
if( id == null ) throw new MessageException( "id == null" );
98
int sid = id.intValue();
100
byte[] hash = (byte[])root.get( "infohash" );
101
if( hash == null ) throw new MessageException( "hash == null" );
102
if( hash.length != 20 ) throw new MessageException( "hash.length != 20: " +hash.length );
104
Map info = (Map)root.get( "info" );
106
return new AZSessionSyn( hash, sid, info, version );
110
public void destroy() {
111
if( buffer != null ) buffer.returnToPool();