| 1152 | |
| 1153 | |
| 1154 | void CKnownFile::CreateOfferedFilePacket( |
| 1155 | CMemFile *files, |
| 1156 | CServer *pServer, |
| 1157 | CUpDownClient *pClient) { |
| 1158 | |
| 1159 | // This function is used for offering files to the local server and for sending |
| 1160 | // shared files to some other client. In each case we send our IP+Port only, if |
| 1161 | // we have a HighID. |
| 1162 | |
| 1163 | wxCHECK_RET(!(pClient && pServer), "pClient and pServer cannot both be non-null"); |
| 1164 | |
| 1165 | SetPublishedED2K(true); |
| 1166 | files->WriteHash(GetFileHash()); |
| 1167 | |
| 1168 | uint32 nClientID = 0; |
| 1169 | uint16 nClientPort = 0; |
| 1170 | |
| 1171 | if (pServer) { |
| 1172 | if (pServer->GetTCPFlags() & SRV_TCPFLG_COMPRESSION) { |
| 1173 | #define FILE_COMPLETE_ID 0xfbfbfbfb |
| 1174 | #define FILE_COMPLETE_PORT 0xfbfb |
| 1175 | #define FILE_INCOMPLETE_ID 0xfcfcfcfc |
| 1176 | #define FILE_INCOMPLETE_PORT 0xfcfc |
| 1177 | // complete file: ip 251.251.251 (0xfbfbfbfb) port 0xfbfb |
| 1178 | // incomplete file: op 252.252.252 (0xfcfcfcfc) port 0xfcfc |
| 1179 | if (GetStatus() == PS_COMPLETE) { |
| 1180 | nClientID = FILE_COMPLETE_ID; |
| 1181 | nClientPort = FILE_COMPLETE_PORT; |
| 1182 | } else { |
| 1183 | nClientID = FILE_INCOMPLETE_ID; |
| 1184 | nClientPort = FILE_INCOMPLETE_PORT; |
| 1185 | } |
| 1186 | } else { |
| 1187 | if (theApp->IsConnectedED2K() && !::IsLowID(theApp->GetED2KID())){ |
| 1188 | nClientID = theApp->GetID(); |
| 1189 | nClientPort = thePrefs::GetPort(); |
| 1190 | } |
| 1191 | } |
| 1192 | } else { |
| 1193 | // Do not merge this with the above case - this one |
| 1194 | // also checks Kad status. |
| 1195 | if (theApp->IsConnected() && !theApp->IsFirewalled()) { |
| 1196 | nClientID = theApp->GetID(); |
| 1197 | nClientPort = thePrefs::GetPort(); |
| 1198 | } |
| 1199 | } |
| 1200 | |
| 1201 | files->WriteUInt32(nClientID); |
| 1202 | files->WriteUInt16(nClientPort); |
| 1203 | |
| 1204 | TagPtrList tags; |
| 1205 | |
| 1206 | // The printable filename is used because it's destined for another user. |
| 1207 | tags.push_back(new CTagString(FT_FILENAME, GetFileName().GetPrintable())); |
| 1208 | |
| 1209 | if (pClient && pClient->GetVBTTags()) { |
| 1210 | tags.push_back(new CTagVarInt(FT_FILESIZE, GetFileSize())); |
| 1211 | } else { |
no test coverage detected