Skip to content

Commit

Permalink
Merge pull request #411 from DRK3/IPFSCompatibleCIDs
Browse files Browse the repository at this point in the history
feat: Local CAS now uses IPFS-compatible CIDs
  • Loading branch information
fqutishat authored May 20, 2021
2 parents 4fd4d92 + 3ec5760 commit 8e15c53
Show file tree
Hide file tree
Showing 20 changed files with 1,021 additions and 82 deletions.
226 changes: 225 additions & 1 deletion cmd/orb-server/go.sum

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions cmd/orb-server/startcmd/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ const (
ipfsURLEnvKey = "IPFS_URL"
ipfsURLFlagUsage = "The URL of the IPFS Content Addressable Storage(CAS). " + commonEnvVarUsageText + ipfsURLEnvKey

cidVersionFlagName = "cid-version"
cidVersionEnvKey = "CID_VERSION"
cidVersionFlagUsage = "The version of the CID format to use for generating CIDs. " +
"Supported options: 0, 1. If not set, defaults to 1." + commonEnvVarUsageText + cidVersionEnvKey

batchWriterTimeoutFlagName = "batch-writer-timeout"
batchWriterTimeoutFlagShorthand = "b"
batchWriterTimeoutEnvKey = "BATCH_WRITER_TIMEOUT"
Expand Down Expand Up @@ -221,6 +226,7 @@ type orbParameters struct {
batchWriterTimeout time.Duration
casType string
ipfsURL string
useV0CIDs bool
dbParameters *dbParameters
logLevel string
methodContext []string
Expand Down Expand Up @@ -303,6 +309,19 @@ func getOrbParameters(cmd *cobra.Command) (*orbParameters, error) {
return nil, err
}

cidVersionString, err := cmdutils.GetUserSetVarFromString(cmd, cidVersionFlagName, cidVersionEnvKey, true)
if err != nil {
return nil, err
}

var useV0CIDs bool

if cidVersionString == "0" {
useV0CIDs = true
} else if cidVersionString != "1" && cidVersionString != "" { // default to v1 if no version specified
return nil, fmt.Errorf("invalid CID version specified. Must be either 0 or 1")
}

batchWriterTimeoutStr, err := cmdutils.GetUserSetVarFromString(cmd, batchWriterTimeoutFlagName, batchWriterTimeoutEnvKey, true)
if err != nil {
return nil, err
Expand Down Expand Up @@ -442,6 +461,7 @@ func getOrbParameters(cmd *cobra.Command) (*orbParameters, error) {
allowedOrigins: allowedOrigins,
casType: casType,
ipfsURL: ipfsURL,
useV0CIDs: useV0CIDs,
batchWriterTimeout: batchWriterTimeout,
anchorCredentialParams: anchorCredentialParams,
dbParameters: dbParams,
Expand Down Expand Up @@ -629,6 +649,7 @@ func createFlags(startCmd *cobra.Command) {
startCmd.Flags().StringP(httpSignaturesEnabledFlagName, httpSignaturesEnabledShorthand, "", httpSignaturesEnabledUsage)
startCmd.Flags().StringP(casTypeFlagName, casTypeFlagShorthand, "", casTypeFlagUsage)
startCmd.Flags().StringP(ipfsURLFlagName, ipfsURLFlagShorthand, "", ipfsURLFlagUsage)
startCmd.Flags().String(cidVersionFlagName, "1", cidVersionFlagUsage)
startCmd.Flags().StringP(didNamespaceFlagName, didNamespaceFlagShorthand, "", didNamespaceFlagUsage)
startCmd.Flags().StringArrayP(didAliasesFlagName, didAliasesFlagShorthand, []string{}, didAliasesFlagUsage)
startCmd.Flags().StringArrayP(allowedOriginsFlagName, allowedOriginsFlagShorthand, []string{}, allowedOriginsFlagUsage)
Expand Down
29 changes: 29 additions & 0 deletions cmd/orb-server/startcmd/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,34 @@ func TestStartCmdWithBlankEnvVar(t *testing.T) {
})
}

func TestStartCmdWithInvalidCIDVersion(t *testing.T) {
startCmd := GetStartCmd()

args := []string{
"--" + hostURLFlagName, "localhost:8247",
"--" + externalEndpointFlagName, "orb.example.com",
"--" + ipfsURLFlagName, "localhost:8081",
"--" + casTypeFlagName, "ipfs",
"--" + vctURLFlagName, "localhost:8081",
"--" + cidVersionFlagName, "-1",
"--" + batchWriterTimeoutFlagName, "700",
"--" + maxWitnessDelayFlagName, "600",
"--" + signWithLocalWitnessFlagName, "false",
"--" + startupDelayFlagName, "1",
"--" + didNamespaceFlagName, "namespace", "--" + databaseTypeFlagName, databaseTypeMemOption,
"--" + kmsSecretsDatabaseTypeFlagName, databaseTypeMemOption,
"--" + anchorCredentialSignatureSuiteFlagName, "suite",
"--" + anchorCredentialDomainFlagName, "domain.com",
"--" + anchorCredentialIssuerFlagName, "issuer.com",
"--" + anchorCredentialURLFlagName, "peer.com",
"--" + LogLevelFlagName, log.ParseString(log.ERROR),
}
startCmd.SetArgs(args)

err := startCmd.Execute()
require.EqualError(t, err, "invalid CID version specified. Must be either 0 or 1")
}

func TestStartCmdCreateKMSFailure(t *testing.T) {
t.Run("KMS fails (DB)", func(t *testing.T) {
startCmd := GetStartCmd()
Expand Down Expand Up @@ -521,6 +549,7 @@ func TestStartCmdValidArgs(t *testing.T) {
"--" + hostURLFlagName, "localhost:8247",
"--" + externalEndpointFlagName, "orb.example.com",
"--" + ipfsURLFlagName, "localhost:8081",
"--" + cidVersionFlagName, "0",
"--" + batchWriterTimeoutFlagName, "700",
"--" + maxWitnessDelayFlagName, "600",
"--" + signWithLocalWitnessFlagName, "false",
Expand Down
6 changes: 3 additions & 3 deletions cmd/orb-server/startcmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,12 @@ func startOrbServices(parameters *orbParameters) error {

switch parameters.casType {
case "ipfs":
coreCasClient = ipfscas.New(parameters.ipfsURL)
coreCasClient = ipfscas.New(parameters.ipfsURL, parameters.useV0CIDs)
anchorCasWriter = orbcaswriter.New(coreCasClient, "ipfs")
case "local":
var err error

coreCasClient, err = casstore.New(storeProviders.provider)
coreCasClient, err = casstore.New(storeProviders.provider, parameters.useV0CIDs)
if err != nil {
return err
}
Expand Down Expand Up @@ -325,7 +325,7 @@ func startOrbServices(parameters *orbParameters) error {

var ipfsReader *ipfscas.Client
if parameters.ipfsURL != "" {
ipfsReader = ipfscas.New(parameters.ipfsURL)
ipfsReader = ipfscas.New(parameters.ipfsURL, false)
}

casResolver := resolver.New(coreCasClient, ipfsReader, httpClient)
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ require (
github.com/igor-pavlenko/httpsignatures-go v0.0.21
github.com/ipfs/go-cid v0.0.7
github.com/ipfs/go-ipfs-api v0.2.0
github.com/ipfs/go-merkledag v0.2.3
github.com/ipfs/go-unixfs v0.2.6
github.com/mr-tron/base58 v1.2.0
github.com/multiformats/go-multihash v0.0.14
github.com/ory/dockertest/v3 v3.6.3
Expand Down
Loading

0 comments on commit 8e15c53

Please sign in to comment.