Creare un'identità pari
L'API di Identity Manager consente di creare un'identità peer da usare in una rete peer.
Quando si crea un'identità peer, è possibile fornire le informazioni facoltative seguenti:
- classificatore
- Nome amichevole
- Provider di servizi di crittografia
Nota
Ogni volta che è possibile, riutilizzare un'identità peer.
Esempio di creazione ed eliminazione di un'identità pari
Il frammento di codice seguente illustra come creare ed eliminare un'identità peer usando un classificatore e un nome descrittivo.
#define UNICODE
#include <p2p.h>
#include <stdio.h>
#pragma comment(lib, "p2p.lib")
//-----------------------------------------------------------------------------
// Function: CreateIdentity
//
// Purpose: Creates a new Identity.
//
// Returns: HRESULT
//
HRESULT CreateIdentity(PWSTR pwzFriendlyName)
{
HRESULT hr = S_OK;
PWSTR pwzClassifier = L"GroupMember";
PWSTR pwzIdentity = NULL;
hr = PeerIdentityCreate(pwzClassifier, pwzFriendlyName, 0, &pwzIdentity);
if (FAILED(hr))
{
printf("Failed to create identity.");
}
else
{
printf("Identity: %s", pwzFriendlyName);
}
PeerFreeData(pwzIdentity);
return hr;
}
//-----------------------------------------------------------------------------
// Function: DeleteIdentity
//
// Purpose: Delete the identity created by CreateIdentity
//
// Returns: HRESULT
//
HRESULT DeleteIdentity()
{
HRESULT hr = S_OK;
if (g_pwzIdentity)
{
hr = PeerIdentityDelete(g_pwzIdentity);
g_pwzIdentity = NULL;
}
return hr;
}