diff --git a/cmd/flags.go b/cmd/flags.go index 70a59ce00c16fcd834dcd50987b12626c10f8504..8d9c827f2b38cb2ff1668cc9431922fc32eaa99e 100644 --- a/cmd/flags.go +++ b/cmd/flags.go @@ -150,6 +150,7 @@ const ( udBatchAddFlag = "batchadd" ///////////////// pickup subcommand flags ////////////////////////////// - pickupGW = "gateway" - pickupID = "id" + pickupGW = "gateway" + pickupID = "id" + pickupEphID = "ephid" ) diff --git a/cmd/pickup.go b/cmd/pickup.go index 92331266e26c41cb6a67f3f6ea52ff7108f580af..ee4afbe53c923e9ec864e6a5b20536fe91b78a01 100644 --- a/cmd/pickup.go +++ b/cmd/pickup.go @@ -9,6 +9,7 @@ package cmd import ( + "encoding/binary" "fmt" "time" @@ -55,22 +56,37 @@ var pickupCmd = &cobra.Command{ ndf := user.GetStorage().GetNDF() gwID := getGatewayID(ndf) - clientID := parseRecipient(viper.GetString(pickupID)) + clientIDStr := viper.GetString(pickupID) + var clientID *id.ID + if clientIDStr != "" { + clientID = parseRecipient(viper.GetString(pickupID)) + } + eID := viper.GetInt64(pickupEphID) + if eID != 0 { + fmt.Printf("EphID Override: %d\n", eID) + } // First we get round info, then we use the timestamps to // calculate the right ephID and retrieve the right bloom filter roundInfos := dumpRounds(roundIDs, user) for i := range roundInfos { ri := roundInfos[i] - ephIDs := getEphID(clientID, uint(ri.AddressSpaceSize), - ri.Timestamps[states.QUEUED]) + var ephIDs []ephemeral.Id + if clientID != nil { + ephIDs = getEphID(clientID, + uint(ri.AddressSpaceSize), + ri.Timestamps[states.QUEUED]) + } else { + ephIDs = append(ephIDs, int2EphID(eID, + uint(ri.AddressSpaceSize))) + } for j := range ephIDs { ephID := ephIDs[j] fmt.Printf("Getting messages for %s, %d\n", - ri.ID, ephID.Id.Int64()) + ri.ID, ephID.Int64()) msgRsp, err := getMessagesFromRound(gwID, ri.ID, - ephID.Id, + ephID, user.GetComms()) if err != nil { fmt.Printf("\n\nround pickup: %+v\n\n", @@ -95,11 +111,37 @@ func init() { "id to check") bindFlagHelper(pickupID, pickupCmd) + pickupCmd.Flags().Int64P(pickupEphID, "e", 0, + "ignore id lookup and use this specific eph id (signed int)") + bindFlagHelper(pickupEphID, pickupCmd) + rootCmd.AddCommand(pickupCmd) } +func int2EphID(in int64, addrSize uint) ephemeral.Id { + var out [8]byte + mask := uint64(0xFFFFFFFFFFFFFFFF) >> (64 - addrSize) + + // NOTE: This is just reversing the Int64() function. I have + // no idea why it was done this way... + x := in + if x < 0 { + x = ^x + x = x << 1 + x = x | 1 + } else { + x = x << 1 + } + + shifted := uint64(x) & mask + fmt.Printf("Shifted: %d, %d, %d, %d\n", addrSize, mask, in, shifted) + + binary.BigEndian.PutUint64(out[:], shifted) + return ephemeral.Id(out) +} + func getEphID(id *id.ID, addrSize uint, - roundStart time.Time) []ephemeral.ProtoIdentity { + roundStart time.Time) []ephemeral.Id { fmt.Printf("Getting EphIDs for %s", roundStart) @@ -115,7 +157,12 @@ func getEphID(id *id.ID, addrSize uint, jww.FATAL.Panicf("No ephemeral ids found!") } - return ephIDs + eIDs := make([]ephemeral.Id, len(ephIDs)) + for i := range ephIDs { + eIDs[i] = ephIDs[i].Id + } + + return eIDs } func getGatewayID(ndf *ndf.NetworkDefinition) *id.ID { gateways := ndf.Gateways