Skip to content

Commit

Permalink
Merge branch 'master' into 0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Lesterpig committed May 27, 2016
2 parents 4ee28ac + 3fa6461 commit 9de8dd5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
5 changes: 3 additions & 2 deletions dfssc/cmd/unregister.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ var unregisterCmd = &cobra.Command{
}

// Confirmation
var ready string
var passphrase, ready string
_ = readPassword(&passphrase, false)
readStringParam("Do you REALLY want to delete "+cert.Subject.CommonName+"? Type 'yes' to confirm", "", &ready)
if ready != "yes" {
fmt.Fprintln(os.Stderr, "Unregistering aborted!")
os.Exit(1)
}

err = user.Unregister()
err = user.Unregister(passphrase)
if err != nil {
fmt.Fprintln(os.Stderr, "Cannot unregister:", err.Error())
os.Exit(2)
Expand Down
30 changes: 17 additions & 13 deletions dfssc/user/unregister.go
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
package user

import (
"errors"

pb "dfss/dfssp/api"
"dfss/dfssc/common"
"dfss/dfssc/security"
"dfss/dfssp/api"
"dfss/net"
"github.com/spf13/viper"
"golang.org/x/net/context"
"google.golang.org/grpc"
)

// Unregister a user from the platform
func Unregister() error {
client, err := connect()
func Unregister(passphrase string) error {
auth := security.NewAuthContainer(passphrase)
ca, cert, key, err := auth.LoadFiles()
if err != nil {
return err
}

conn, err := net.Connect(viper.GetString("platform_addrport"), cert, key, ca, nil)
if err != nil {
return err
}

// Stop the context if it takes too long for the platform to answer
client := api.NewPlatformClient(conn)
ctx, cancel := context.WithTimeout(context.Background(), net.DefaultTimeout)
defer cancel()
response, err := client.Unregister(ctx, &pb.Empty{})
response, err := client.Unregister(ctx, &api.Empty{})

if err != nil {
return errors.New(grpc.ErrorDesc(err))
}
if response.Code != pb.ErrorCode_SUCCESS {
return errors.New(response.Message)
return err
}

return nil
return common.EvaluateErrorCodeResponse(response)
}
8 changes: 3 additions & 5 deletions dfssp/contract/ready.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ var ReadySignTimeout = time.Minute
func ReadySign(db *mgdb.MongoManager, rooms *common.WaitingGroupMap, ctx *context.Context, in *api.ReadySignRequest) *api.LaunchSignature {
roomID := "ready_" + in.ContractUuid
channel, _, first := rooms.Join(roomID)
cn := net.GetCN(ctx)
defer rooms.Unjoin(roomID, channel)

cn := net.GetCN(ctx)
// Check UUID
if !bson.IsObjectIdHex(in.ContractUuid) {
return &api.LaunchSignature{ErrorCode: &api.ErrorCode{Code: api.ErrorCode_INVARG}}
Expand Down Expand Up @@ -71,10 +72,8 @@ func ReadySign(db *mgdb.MongoManager, rooms *common.WaitingGroupMap, ctx *contex
return &api.LaunchSignature{ErrorCode: &api.ErrorCode{Code: api.ErrorCode_INVARG}}
}
case <-(*ctx).Done(): // Client's disconnection
rooms.Unjoin(roomID, channel)
return &api.LaunchSignature{ErrorCode: &api.ErrorCode{Code: api.ErrorCode_INVARG}}
case <-timeout: // Someone has not confirmed the signature within the delay
rooms.Unjoin(roomID, channel)
return &api.LaunchSignature{ErrorCode: &api.ErrorCode{Code: api.ErrorCode_TIMEOUT, Message: "timeout for ready signal"}}
}
}
Expand All @@ -86,6 +85,7 @@ func ReadySign(db *mgdb.MongoManager, rooms *common.WaitingGroupMap, ctx *contex
func masterReadyRoutine(db *mgdb.MongoManager, rooms *common.WaitingGroupMap, contractUUID string) {
roomID := "ready_" + contractUUID
channel, oldMessages, _ := rooms.Join(roomID)
defer rooms.Unjoin(roomID, channel)

// Push oldMessages into the channel.
// It is safe as this sould be a very small slice (the room is just created).
Expand All @@ -102,7 +102,6 @@ func masterReadyRoutine(db *mgdb.MongoManager, rooms *common.WaitingGroupMap, co
ready: true,
data: "",
}) // This represents a "error" response
rooms.Unjoin(roomID, channel)
return
}

Expand Down Expand Up @@ -132,7 +131,6 @@ func masterReadyRoutine(db *mgdb.MongoManager, rooms *common.WaitingGroupMap, co
}
}

rooms.Unjoin(roomID, channel)
}

// FindAndUpdatePendingSigner is a utility function to return the state of current signers readiness.
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

// Version represents the current version of the DFSS software suite
const Version = "0.3.0"
const Version = "0.3.1"

// VersionCmd is the cobra command common to all dfss modules
var VersionCmd = &cobra.Command{
Expand Down

0 comments on commit 9de8dd5

Please sign in to comment.