diff options
Diffstat (limited to 'src/gnunet/message/factory.go')
-rw-r--r-- | src/gnunet/message/factory.go | 61 |
1 files changed, 31 insertions, 30 deletions
diff --git a/src/gnunet/message/factory.go b/src/gnunet/message/factory.go index 23da078..8f664b0 100644 --- a/src/gnunet/message/factory.go +++ b/src/gnunet/message/factory.go | |||
@@ -20,95 +20,96 @@ package message | |||
20 | 20 | ||
21 | import ( | 21 | import ( |
22 | "fmt" | 22 | "fmt" |
23 | "gnunet/enums" | ||
23 | ) | 24 | ) |
24 | 25 | ||
25 | // NewEmptyMessage creates a new empty message object for the given type. | 26 | // NewEmptyMessage creates a new empty message object for the given type. |
26 | func NewEmptyMessage(msgType uint16) (Message, error) { | 27 | func NewEmptyMessage(msgType enums.MsgType) (Message, error) { |
27 | switch msgType { | 28 | switch msgType { |
28 | //------------------------------------------------------------------ | 29 | //------------------------------------------------------------------ |
29 | // Transport | 30 | // Transport |
30 | //------------------------------------------------------------------ | 31 | //------------------------------------------------------------------ |
31 | case TRANSPORT_TCP_WELCOME: | 32 | case enums.MSG_TRANSPORT_TCP_WELCOME: |
32 | return NewTransportTCPWelcomeMsg(nil), nil | 33 | return NewTransportTCPWelcomeMsg(nil), nil |
33 | case HELLO: | 34 | case enums.MSG_HELLO: |
34 | return NewHelloMsg(nil), nil | 35 | return NewHelloMsg(nil), nil |
35 | case TRANSPORT_SESSION_QUOTA: | 36 | case enums.MSG_TRANSPORT_SESSION_QUOTA: |
36 | return NewSessionQuotaMsg(0), nil | 37 | return NewSessionQuotaMsg(0), nil |
37 | case TRANSPORT_SESSION_SYN: | 38 | case enums.MSG_TRANSPORT_SESSION_SYN: |
38 | return NewSessionSynMsg(), nil | 39 | return NewSessionSynMsg(), nil |
39 | case TRANSPORT_SESSION_SYN_ACK: | 40 | case enums.MSG_TRANSPORT_SESSION_SYN_ACK: |
40 | return NewSessionSynAckMsg(), nil | 41 | return NewSessionSynAckMsg(), nil |
41 | case TRANSPORT_SESSION_ACK: | 42 | case enums.MSG_TRANSPORT_SESSION_ACK: |
42 | return new(SessionAckMsg), nil | 43 | return new(SessionAckMsg), nil |
43 | case TRANSPORT_PING: | 44 | case enums.MSG_TRANSPORT_PING: |
44 | return NewTransportPingMsg(nil, nil), nil | 45 | return NewTransportPingMsg(nil, nil), nil |
45 | case TRANSPORT_PONG: | 46 | case enums.MSG_TRANSPORT_PONG: |
46 | return NewTransportPongMsg(0, nil), nil | 47 | return NewTransportPongMsg(0, nil), nil |
47 | case TRANSPORT_SESSION_KEEPALIVE: | 48 | case enums.MSG_TRANSPORT_SESSION_KEEPALIVE: |
48 | return NewSessionKeepAliveMsg(), nil | 49 | return NewSessionKeepAliveMsg(), nil |
49 | 50 | ||
50 | //------------------------------------------------------------------ | 51 | //------------------------------------------------------------------ |
51 | // Core | 52 | // Core |
52 | //------------------------------------------------------------------ | 53 | //------------------------------------------------------------------ |
53 | case CORE_EPHEMERAL_KEY: | 54 | case enums.MSG_CORE_EPHEMERAL_KEY: |
54 | return NewEphemeralKeyMsg(), nil | 55 | return NewEphemeralKeyMsg(), nil |
55 | 56 | ||
56 | //------------------------------------------------------------------ | 57 | //------------------------------------------------------------------ |
57 | // DHT | 58 | // DHT |
58 | //------------------------------------------------------------------ | 59 | //------------------------------------------------------------------ |
59 | case DHT_CLIENT_PUT: | 60 | case enums.MSG_DHT_CLIENT_PUT: |
60 | return NewDHTClientPutMsg(nil, 0, nil), nil | 61 | return NewDHTClientPutMsg(nil, 0, nil), nil |
61 | case DHT_CLIENT_GET: | 62 | case enums.MSG_DHT_CLIENT_GET: |
62 | return NewDHTClientGetMsg(nil), nil | 63 | return NewDHTClientGetMsg(nil), nil |
63 | case DHT_CLIENT_GET_STOP: | 64 | case enums.MSG_DHT_CLIENT_GET_STOP: |
64 | return NewDHTClientGetStopMsg(nil), nil | 65 | return NewDHTClientGetStopMsg(nil), nil |
65 | case DHT_CLIENT_RESULT: | 66 | case enums.MSG_DHT_CLIENT_RESULT: |
66 | return NewDHTClientResultMsg(nil), nil | 67 | return NewDHTClientResultMsg(nil), nil |
67 | case DHT_CLIENT_GET_RESULTS_KNOWN: | 68 | case enums.MSG_DHT_CLIENT_GET_RESULTS_KNOWN: |
68 | return NewDHTClientGetResultsKnownMsg(nil), nil | 69 | return NewDHTClientGetResultsKnownMsg(nil), nil |
69 | 70 | ||
70 | //------------------------------------------------------------------ | 71 | //------------------------------------------------------------------ |
71 | // DHT-P2P | 72 | // DHT-P2P |
72 | //------------------------------------------------------------------ | 73 | //------------------------------------------------------------------ |
73 | case DHT_P2P_HELLO: | 74 | case enums.MSG_DHT_P2P_HELLO: |
74 | return NewDHTP2PHelloMsg(), nil | 75 | return NewDHTP2PHelloMsg(), nil |
75 | case DHT_P2P_GET: | 76 | case enums.MSG_DHT_P2P_GET: |
76 | return NewDHTP2PGetMsg(), nil | 77 | return NewDHTP2PGetMsg(), nil |
77 | case DHT_P2P_PUT: | 78 | case enums.MSG_DHT_P2P_PUT: |
78 | return NewDHTP2PPutMsg(), nil | 79 | return NewDHTP2PPutMsg(), nil |
79 | case DHT_P2P_RESULT: | 80 | case enums.MSG_DHT_P2P_RESULT: |
80 | return NewDHTP2PResultMsg(), nil | 81 | return NewDHTP2PResultMsg(), nil |
81 | 82 | ||
82 | //------------------------------------------------------------------ | 83 | //------------------------------------------------------------------ |
83 | // GNS | 84 | // GNS |
84 | //------------------------------------------------------------------ | 85 | //------------------------------------------------------------------ |
85 | case GNS_LOOKUP: | 86 | case enums.MSG_GNS_LOOKUP: |
86 | return NewGNSLookupMsg(), nil | 87 | return NewGNSLookupMsg(), nil |
87 | case GNS_LOOKUP_RESULT: | 88 | case enums.MSG_GNS_LOOKUP_RESULT: |
88 | return NewGNSLookupResultMsg(0), nil | 89 | return NewGNSLookupResultMsg(0), nil |
89 | 90 | ||
90 | //------------------------------------------------------------------ | 91 | //------------------------------------------------------------------ |
91 | // Namecache | 92 | // Namecache |
92 | //------------------------------------------------------------------ | 93 | //------------------------------------------------------------------ |
93 | case NAMECACHE_LOOKUP_BLOCK: | 94 | case enums.MSG_NAMECACHE_LOOKUP_BLOCK: |
94 | return NewNamecacheLookupMsg(nil), nil | 95 | return NewNamecacheLookupMsg(nil), nil |
95 | case NAMECACHE_LOOKUP_BLOCK_RESPONSE: | 96 | case enums.MSG_NAMECACHE_LOOKUP_BLOCK_RESPONSE: |
96 | return NewNamecacheLookupResultMsg(), nil | 97 | return NewNamecacheLookupResultMsg(), nil |
97 | case NAMECACHE_BLOCK_CACHE: | 98 | case enums.MSG_NAMECACHE_BLOCK_CACHE: |
98 | return NewNamecacheCacheMsg(nil), nil | 99 | return NewNamecacheCacheMsg(nil), nil |
99 | case NAMECACHE_BLOCK_CACHE_RESPONSE: | 100 | case enums.MSG_NAMECACHE_BLOCK_CACHE_RESPONSE: |
100 | return NewNamecacheCacheResponseMsg(), nil | 101 | return NewNamecacheCacheResponseMsg(), nil |
101 | 102 | ||
102 | //------------------------------------------------------------------ | 103 | //------------------------------------------------------------------ |
103 | // Revocation | 104 | // Revocation |
104 | //------------------------------------------------------------------ | 105 | //------------------------------------------------------------------ |
105 | case REVOCATION_QUERY: | 106 | case enums.MSG_REVOCATION_QUERY: |
106 | return NewRevocationQueryMsg(nil), nil | 107 | return NewRevocationQueryMsg(nil), nil |
107 | case REVOCATION_QUERY_RESPONSE: | 108 | case enums.MSG_REVOCATION_QUERY_RESPONSE: |
108 | return NewRevocationQueryResponseMsg(true), nil | 109 | return NewRevocationQueryResponseMsg(true), nil |
109 | case REVOCATION_REVOKE: | 110 | case enums.MSG_REVOCATION_REVOKE: |
110 | return NewRevocationRevokeMsg(nil), nil | 111 | return NewRevocationRevokeMsg(nil), nil |
111 | case REVOCATION_REVOKE_RESPONSE: | 112 | case enums.MSG_REVOCATION_REVOKE_RESPONSE: |
112 | return NewRevocationRevokeResponseMsg(false), nil | 113 | return NewRevocationRevokeResponseMsg(false), nil |
113 | } | 114 | } |
114 | return nil, fmt.Errorf("unknown message type %d", msgType) | 115 | return nil, fmt.Errorf("unknown message type %d", msgType) |