diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /utils/vmpi/vmpi_transfer | |
| download | archived-source-engine-2018-hl2-src-master.tar.xz archived-source-engine-2018-hl2-src-master.zip | |
Diffstat (limited to 'utils/vmpi/vmpi_transfer')
| -rw-r--r-- | utils/vmpi/vmpi_transfer/vmpi_transfer.cpp | 172 | ||||
| -rw-r--r-- | utils/vmpi/vmpi_transfer/vmpi_transfer.h | 14 | ||||
| -rw-r--r-- | utils/vmpi/vmpi_transfer/vmpi_transfer.vpc | 155 |
3 files changed, 341 insertions, 0 deletions
diff --git a/utils/vmpi/vmpi_transfer/vmpi_transfer.cpp b/utils/vmpi/vmpi_transfer/vmpi_transfer.cpp new file mode 100644 index 0000000..fadf3fd --- /dev/null +++ b/utils/vmpi/vmpi_transfer/vmpi_transfer.cpp @@ -0,0 +1,172 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//============================================================================= + +#include <windows.h> +#include "vmpi.h" +#include "vmpi_transfer.h" +#include "cmdlib.h" +#include "tier0/icommandline.h" +#include "vmpi_tools_shared.h" +#include "tools_minidump.h" +#include <conio.h> + + +void MyDisconnectHandler( int procID, const char *pReason ) +{ + Error( "Premature disconnect.\n" ); +} + +void DownloadFile( const char *pCachePath, const char *pRemoteFileBase, const char *pFilename ) +{ + // Setup local and remote filenames. + char remoteFilename[MAX_PATH]; + char localFilename[MAX_PATH]; + V_ComposeFileName( pRemoteFileBase, pFilename, remoteFilename, sizeof( remoteFilename ) ); + V_ComposeFileName( pCachePath, pFilename, localFilename, sizeof( localFilename ) ); + + // Read the file in. + FileHandle_t fpSrc = g_pFileSystem->Open( remoteFilename, "rb" ); + if ( fpSrc == FILESYSTEM_INVALID_HANDLE ) + { + Error( "Unable to open %s on master.\n", remoteFilename ); + } + + unsigned int fileSize = g_pFileSystem->Size( fpSrc ); + CUtlVector<char> data; + data.SetSize( fileSize ); + g_pFileSystem->Read( data.Base(), fileSize, fpSrc ); + g_pFileSystem->Close( fpSrc ); + + // Now write the file to disk. + FILE *fpDest = fopen( localFilename, "wb" ); + if ( !fpDest ) + { + Error( "Can't open %s for writing.\n", localFilename ); + } + fwrite( data.Base(), 1, data.Count(), fpDest ); + fclose( fpDest ); + +Warning( "Got file: %s\n", pFilename ); +} + +#if 0 +SpewRetval_t MySpewFunc( SpewType_t spewType, const tchar *pMsg ) +{ + printf( "%s", pMsg ); + if ( spewType == SPEW_ERROR ) + { + printf( "\nWaiting for keypress to quit...\n" ); + getch(); + TerminateProcess( GetCurrentProcess(), 1 ); + } + + return SPEW_CONTINUE; +} +#endif + +int RunVMPITransferWorker( int argc, char **argv ) +{ + if ( !VMPI_Init( argc, argv, NULL, MyDisconnectHandler, VMPI_RUN_NETWORKED, true ) ) + { + return 1; + } + + SetupToolsMinidumpHandler( VMPI_ExceptionFilter ); + + if ( !FileSystem_Init( ".", 0, FS_INIT_COMPATIBILITY_MODE ) ) + return 1; + + ICommandLine *pCommandLine = CommandLine(); + + // Look for the cache path and file base args. + const char *pCachePath = pCommandLine->ParmValue( "-CachePath", (char*)NULL ); + if ( !pCachePath ) + Error( "No -CachePath specified." ); + + const char *pRemoteFileBase = pCommandLine->ParmValue( "-mpi_filebase", (char*)NULL ); + if ( !pRemoteFileBase ) + Error( "No -mpi_filebase specified." ); + + // Now just ask the master for each file. + for ( int i=1; i < pCommandLine->ParmCount()-1; i++ ) + { + const char *pParm = pCommandLine->GetParm( i ); + if ( V_stricmp( pParm, "-mpi_file" ) == 0 ) + { + const char *pNextParm = pCommandLine->GetParm( i+1 ); + DownloadFile( pCachePath, pRemoteFileBase, pNextParm ); + ++i; + } + } + + // Ok, we're done. Write the status file so the service knows all the files are ready to go. + char statusFilename[MAX_PATH]; + V_ComposeFileName( pCachePath, "ReadyToGo.txt", statusFilename, sizeof( statusFilename ) ); + FILE *fp = fopen( statusFilename, "wb" ); + fclose( fp ); + + return 0; +} + + +// In this mode, we just initialize VMPI appropriately, and it'll host out the specified files. +// The command line to vmpi_transfer is -PatchHost -PatchDirectory <directory> +// Sample: vmpi_transfer -PatchHost -mpi_PatchDirectory \\fileserver\vmpi\patch1 -mpi_PatchWorkers <count> <ip1> <ip2>... +// Then it'll tell those workers to connect and it'll send them the files in the specified directory. +int RunVMPITransferMaster( int argc, char **argv ) +{ + // Since we didn't use -mpi_worker on the command line, VMPI will init as the master. + // We put a special character in front of the dependency filename, which tells it the dependencies + // consist of every file in the specified directory. + VMPI_Init_PatchMaster( argc, argv ); + + if ( !FileSystem_Init( ".", 0, FS_INIT_COMPATIBILITY_MODE ) ) + return 1; + + Msg( "Hosting patch files. Press ESC to exit. " ); + while ( 1 ) + { + VMPI_DispatchNextMessage( 100 ); + if ( kbhit() ) + { + if ( getch() == 27 ) + break; + } + } + + return 0; +} + + +// --------------------------------------------------------------------------------- // +// Purpose: This app is used by vmpi_service to acquire the executables for +// a VMPI job. When the service is asked to join a job, it runs this program +// to connect to the VMPI master and download all the exes for the job. +// +// This app is ALSO used to do patches. vmpi_browser_services runs it with a list +// of machines it wants to patch. Then it runs as the VMPI master and instead of +// broadcasting its presence, it sends messages to the specific list of machines. +// --------------------------------------------------------------------------------- // +int main( int argc, char **argv ) +{ + InstallSpewFunction(); + CommandLine()->CreateCmdLine( argc, argv ); + + int ret; + if ( CommandLine()->FindParm( "-PatchHost" ) == 0 ) + { + ret = RunVMPITransferWorker( argc, argv ); + } + else + { + ret = RunVMPITransferMaster( argc, argv ); + } + + CmdLib_Cleanup(); + return ret; +} + + diff --git a/utils/vmpi/vmpi_transfer/vmpi_transfer.h b/utils/vmpi/vmpi_transfer/vmpi_transfer.h new file mode 100644 index 0000000..95c8b67 --- /dev/null +++ b/utils/vmpi/vmpi_transfer/vmpi_transfer.h @@ -0,0 +1,14 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//============================================================================= + +#ifndef VMPI_TRANSFER_H +#define VMPI_TRANSFER_H +#ifdef _WIN32 +#pragma once +#endif + + +#endif // VMPI_TRANSFER_H diff --git a/utils/vmpi/vmpi_transfer/vmpi_transfer.vpc b/utils/vmpi/vmpi_transfer/vmpi_transfer.vpc new file mode 100644 index 0000000..baa9cc6 --- /dev/null +++ b/utils/vmpi/vmpi_transfer/vmpi_transfer.vpc @@ -0,0 +1,155 @@ +//----------------------------------------------------------------------------- +// VMPI_TRANSFER.VPC +// +// Project Script +//----------------------------------------------------------------------------- + +$Macro SRCDIR "..\..\.." +$Macro OUTBINDIR "$SRCDIR\..\game\bin" +$Macro OUTBINNAME "vmpi_transfer" + +$Include "$SRCDIR\vpc_scripts\source_exe_con_base.vpc" + +$Configuration +{ + $Compiler + { + $AdditionalIncludeDirectories "$BASE,..\..\common,.." + $PreprocessorDefinitions "$BASE;MPI;PROTECTED_THINGS_DISABLE" + } + + $Linker + { + $AdditionalDependencies "$BASE ws2_32.lib" + } +} + +$Project "vmpi_transfer" +{ + $Folder "Source Files" + { + $File "..\..\common\vmpi_tools_shared.cpp" + $File "..\..\common\vmpi_tools_shared.h" + $File "vmpi_transfer.cpp" + + $Folder "Common Files" + { + $File "..\..\common\threads.cpp" + $File "..\..\common\pacifier.cpp" + $File "..\..\common\cmdlib.cpp" + $File "..\..\common\tools_minidump.cpp" + $File "..\..\common\tools_minidump.h" + } + + $Folder "Public Files" + { + $File "$SRCDIR\public\filesystem_helpers.cpp" + } + } + + $Folder "Header Files" + { + $File "vmpi_transfer.h" + + $Folder "Common Header Files" + { + $File "..\..\common\cmdlib.h" + $File "..\iphelpers.h" + $File "..\messbuf.h" + $File "..\mysql_wrapper.h" + $File "..\threadhelpers.h" + $File "..\vmpi_defs.h" + $File "..\vmpi_dispatch.h" + $File "..\vmpi_distribute_work.h" + $File "..\vmpi_filesystem.h" + } + + $Folder "Public Header Files" + { + $File "$SRCDIR\public\mathlib\amd3dx.h" + $File "$SRCDIR\public\mathlib\ANORMS.H" + $File "$SRCDIR\public\basehandle.h" + $File "$SRCDIR\public\tier0\basetypes.h" + $File "$SRCDIR\public\tier1\bitbuf.h" + $File "$SRCDIR\public\bitvec.h" + $File "$SRCDIR\public\BSPFILE.H" + $File "$SRCDIR\public\bspflags.h" + $File "$SRCDIR\public\BSPTreeData.h" + $File "$SRCDIR\public\builddisp.h" + $File "$SRCDIR\public\mathlib\bumpvects.h" + $File "$SRCDIR\public\tier1\byteswap.h" + $File "$SRCDIR\public\tier1\characterset.h" + $File "$SRCDIR\public\tier1\checksum_crc.h" + $File "$SRCDIR\public\tier1\checksum_md5.h" + $File "$SRCDIR\public\ChunkFile.h" + $File "$SRCDIR\public\cmodel.h" + $File "$SRCDIR\public\CollisionUtils.h" + $File "$SRCDIR\public\tier0\commonmacros.h" + $File "$SRCDIR\public\mathlib\compressed_vector.h" + $File "$SRCDIR\public\const.h" + $File "$SRCDIR\public\coordsize.h" + $File "$SRCDIR\public\tier0\dbg.h" + $File "$SRCDIR\public\disp_common.h" + $File "$SRCDIR\public\disp_powerinfo.h" + $File "$SRCDIR\public\disp_vertindex.h" + $File "$SRCDIR\public\DispColl_Common.h" + $File "$SRCDIR\public\tier0\fasttimer.h" + $File "$SRCDIR\public\filesystem.h" + $File "$SRCDIR\public\filesystem_helpers.h" + $File "$SRCDIR\public\GameBSPFile.h" + $File "$SRCDIR\public\gametrace.h" + $File "$SRCDIR\public\mathlib\halton.h" + $File "$SRCDIR\public\materialsystem\hardwareverts.h" + $File "$SRCDIR\public\appframework\IAppSystem.h" + $File "$SRCDIR\public\tier0\icommandline.h" + $File "$SRCDIR\public\ihandleentity.h" + $File "$SRCDIR\public\materialsystem\imaterial.h" + $File "$SRCDIR\public\materialsystem\imaterialsystem.h" + $File "$SRCDIR\public\materialsystem\imaterialvar.h" + $File "$SRCDIR\public\tier1\interface.h" + $File "$SRCDIR\public\iscratchpad3d.h" + $File "$SRCDIR\public\ivraddll.h" + $File "$SRCDIR\public\materialsystem\materialsystem_config.h" + $File "$SRCDIR\public\mathlib\mathlib.h" + $File "$SRCDIR\public\tier0\memdbgon.h" + $File "$SRCDIR\public\optimize.h" + $File "$SRCDIR\public\tier0\platform.h" + $File "$SRCDIR\public\tier0\protected_things.h" + $File "$SRCDIR\public\vstdlib\random.h" + $File "$SRCDIR\public\ScratchPad3D.h" + $File "$SRCDIR\public\ScratchPadUtils.h" + $File "$SRCDIR\public\string_t.h" + $File "$SRCDIR\public\tier1\strtools.h" + $File "$SRCDIR\public\studio.h" + $File "$SRCDIR\public\tier1\tokenreader.h" + $File "$SRCDIR\public\trace.h" + $File "$SRCDIR\public\tier1\utlbuffer.h" + $File "$SRCDIR\public\tier1\utldict.h" + $File "$SRCDIR\public\tier1\utlhash.h" + $File "$SRCDIR\public\tier1\utllinkedlist.h" + $File "$SRCDIR\public\tier1\utlmemory.h" + $File "$SRCDIR\public\tier1\utlrbtree.h" + $File "$SRCDIR\public\tier1\utlsymbol.h" + $File "$SRCDIR\public\tier1\utlvector.h" + $File "$SRCDIR\public\vcollide.h" + $File "$SRCDIR\public\mathlib\vector.h" + $File "$SRCDIR\public\mathlib\vector2d.h" + $File "$SRCDIR\public\mathlib\vector4d.h" + $File "$SRCDIR\public\mathlib\vmatrix.h" + $File "..\vmpi.h" + $File "$SRCDIR\public\vphysics_interface.h" + $File "$SRCDIR\public\mathlib\vplane.h" + $File "$SRCDIR\public\tier0\vprof.h" + $File "$SRCDIR\public\vstdlib\vstdlib.h" + $File "$SRCDIR\public\vtf\vtf.h" + $File "$SRCDIR\public\wadtypes.h" + $File "$SRCDIR\public\worldsize.h" + } + } + + $Folder "Link Libraries" + { + $Lib tier2 + $Lib vmpi + } +} |