예제 #1
0
func (ma *mgoAPI) Read(collection string, uuidString string) (found bool, res resource, err error) {
	newSession := ma.session.Copy()
	defer newSession.Close()

	coll := newSession.DB(ma.dbName).C(collection)

	bsonUUID := bson.Binary{Kind: 0x04, Data: []byte(uuid.Parse(uuidString))}

	var bsonResource map[string]interface{}

	if err = coll.Find(bson.M{uuidName: bsonUUID}).One(&bsonResource); err != nil {
		if err == mgo.ErrNotFound {
			return false, res, nil
		}
		return false, res, err
	}

	uuidData := bsonResource["uuid"].(bson.Binary).Data

	res = resource{
		UUID:        uuid.UUID(uuidData).String(),
		Content:     bsonResource["content"],
		ContentType: bsonResource["content-type"].(string),
	}

	return true, res, nil
}
예제 #2
0
파일: intface.go 프로젝트: yangzhao28/zmq3
func (agent *agent_t) handle_beacon() (err error) {

	msg, err := agent.udp.RecvMessage(0)
	if len(msg[0]) != 16 {
		return errors.New("Not a uuid")
	}

	//  If we got a UUID and it's not our own beacon, we have a peer
	uuid := uuid.UUID(msg[0])
	if bytes.Compare(uuid, agent.uuid_bytes) != 0 {
		//  Find or create peer via its UUID string
		uuid_string := uuid.String()
		peer, ok := agent.peers[uuid_string]
		if !ok {
			peer = new_peer(uuid)
			agent.peers[uuid_string] = peer

			//  Report peer joined the network
			agent.pipe.SendMessage("JOINED", uuid_string)
		}
		//  Any activity from the peer means it's alive
		peer.is_alive()
	}
	return
}
예제 #3
0
// DecryptKey decrypts a key from a json blob, returning the private key itself.
func DecryptKey(keyjson []byte, auth string) (*Key, error) {
	// Parse the json into a simple map to fetch the key version
	m := make(map[string]interface{})
	if err := json.Unmarshal(keyjson, &m); err != nil {
		return nil, err
	}
	// Depending on the version try to parse one way or another
	var (
		keyBytes, keyId []byte
		err             error
	)
	if version, ok := m["version"].(string); ok && version == "1" {
		k := new(encryptedKeyJSONV1)
		if err := json.Unmarshal(keyjson, k); err != nil {
			return nil, err
		}
		keyBytes, keyId, err = decryptKeyV1(k, auth)
	} else {
		k := new(encryptedKeyJSONV3)
		if err := json.Unmarshal(keyjson, k); err != nil {
			return nil, err
		}
		keyBytes, keyId, err = decryptKeyV3(k, auth)
	}
	// Handle any decryption errors and return the key
	if err != nil {
		return nil, err
	}
	key := crypto.ToECDSA(keyBytes)
	return &Key{
		Id:         uuid.UUID(keyId),
		Address:    crypto.PubkeyToAddress(key.PublicKey),
		PrivateKey: key,
	}, nil
}
예제 #4
0
func getUUIDString(uuidValue interface{}) string {
	if uuidString, ok := uuidValue.(string); ok {
		return uuidString
	} else if binaryId, ok := uuidValue.(bson.Binary); ok {
		return uuid.UUID(binaryId.Data).String()
	} else {
		fmt.Printf("UUID field is in an unknown format!\n %# v", pretty.Formatter(uuidValue))
		return ""
	}
}
func (ks keyStorePassphrase) GetKey(keyAddr common.Address, auth string) (key *Key, err error) {
	keyBytes, keyId, err := decryptKeyFromFile(ks.keysDirPath, keyAddr, auth)
	if err == nil {
		key = &Key{
			Id:         uuid.UUID(keyId),
			Address:    keyAddr,
			PrivateKey: ToECDSA(keyBytes),
		}
	}
	return
}
예제 #6
0
파일: mappings_test.go 프로젝트: plar/btrfs
func TestNewStruct(t *testing.T) {
	data := make([]byte, 1024, 1024)
	for i := 0; i < len(data); i++ {
		data[i] = byte(i + 1)
	}

	// test seek tag, hex value
	data[0x100] = 0x55
	data[0x101] = 0x66
	data[0x102] = 0x77
	data[0x103] = 0x88
	data[0x104] = 0x99
	data[0x105] = 0xAA
	data[0x106] = 0xBB
	data[0x107] = 0xCC

	// test seek tag, dec value
	data[512] = 0x11
	data[513] = 0x22
	data[514] = 0x33
	data[515] = 0x44
	data[516] = 0x55
	data[517] = 0x66
	data[518] = 0x77
	data[519] = 0x88

	f := &Foo{}
	err := NewStruct(f, bytes.NewReader(data[:]))
	assert.NoError(t, err)
	assert.Equal(t, uint8(0x01), f.F1)
	assert.Equal(t, uint16(0x0302), f.F2)
	assert.Equal(t, uint32(0x07060504), f.F3)
	assert.Equal(t, uint64(0x0f0e0d0c0b0a0908), f.F4)

	assert.Equal(t, uint16(0x1110), f.BB.D.D1)
	assert.Equal(t, uint16(0x1312), f.BB.D.D2)

	assert.Equal(t, uint8(0x14), f.BB.B1)
	assert.Equal(t, uint16(0x1615), f.BB.B2)

	assert.Equal(t, uint64(0xccbbaa9988776655), f.F5)
	assert.Equal(t, uint64(0x8877665544332211), f.F6)
	assert.Equal(t, uint8(0x09), f.F7)

	assert.Equal(t, uuid.UUID([]byte{0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19}), f.UUID)
}
예제 #7
0
func (driver *MesosExecutorDriver) statusUpdateAcknowledgement(from *upid.UPID, pbMsg proto.Message) {
	log.Infoln("Executor statusUpdateAcknowledgement")

	msg := pbMsg.(*mesosproto.StatusUpdateAcknowledgementMessage)
	log.Infof("Receiving status update acknowledgement %v", msg)

	frameworkID := msg.GetFrameworkId()
	taskID := msg.GetTaskId()
	uuid := uuid.UUID(msg.GetUuid())

	if driver.stopped() {
		log.Infof("Ignoring status update acknowledgement %v for task %v of framework %v because the driver is stopped!\n",
			uuid, taskID, frameworkID)
	}

	// Remove the corresponding update.
	delete(driver.updates, uuid.String())
	// Remove the corresponding task.
	delete(driver.tasks, taskID.String())
}
예제 #8
0
// SendStatusUpdate sends status updates to the slave.
func (driver *MesosExecutorDriver) SendStatusUpdate(taskStatus *mesosproto.TaskStatus) (mesosproto.Status, error) {
	log.V(3).Infoln("Sending task status update: ", taskStatus.String())

	if stat := driver.Status(); stat != mesosproto.Status_DRIVER_RUNNING {
		return stat, fmt.Errorf("Unable to SendStatusUpdate, expecting driver.status %s, but got %s", mesosproto.Status_DRIVER_RUNNING, stat)
	}

	if taskStatus.GetState() == mesosproto.TaskState_TASK_STAGING {
		err := fmt.Errorf("Executor is not allowed to send TASK_STAGING status update. Aborting!")
		log.Errorln(err)
		if err0 := driver.stop(mesosproto.Status_DRIVER_ABORTED); err0 != nil {
			log.Errorln("Error while stopping the driver", err0)
		}

		return driver.Status(), err
	}

	// Set up status update.
	update := driver.makeStatusUpdate(taskStatus)
	log.Infof("Executor sending status update %v\n", update.String())

	// Capture the status update.
	driver.lock.Lock()
	driver.updates[uuid.UUID(update.GetUuid()).String()] = update
	driver.lock.Unlock()

	// Put the status update in the message.
	message := &mesosproto.StatusUpdateMessage{
		Update: update,
		Pid:    proto.String(driver.self.String()),
	}
	// Send the message.
	if err := driver.send(driver.slaveUPID, message); err != nil {
		log.Errorf("Failed to send %v: %v\n", message, err)
		return driver.status, err
	}

	return driver.Status(), nil
}
예제 #9
0
func (ma *mgoAPI) Ids(collection string, stopChan chan struct{}, errChan chan error) chan string {
	ids := make(chan string)
	go func() {
		defer close(ids)
		newSession := ma.session.Copy()
		newSession.SetSocketTimeout(30 * time.Second)
		defer newSession.Close()
		coll := newSession.DB(ma.dbName).C(collection)

		iter := coll.Find(nil).Select(bson.M{uuidName: true}).Iter()
		var result map[string]interface{}
		for iter.Next(&result) {
			select {
			case <-stopChan:
				break
			case ids <- uuid.UUID(result["uuid"].(bson.Binary).Data).String():
			}
		}
		if err := iter.Close(); err != nil {
			errChan <- err
		}
	}()
	return ids
}
예제 #10
0
파일: id.go 프로젝트: jonasi/project
func (s sorted) Less(i, j int) bool {
	a, _ := uuid.UUID(s[i]).Time()
	b, _ := uuid.UUID(s[j]).Time()

	return int64(a) < int64(b)
}
예제 #11
0
파일: id.go 프로젝트: jonasi/project
func (i ID) Equal(id ID) bool {
	return uuid.Equal(uuid.UUID(i), uuid.UUID(id))
}
예제 #12
0
파일: id.go 프로젝트: jonasi/project
func (i ID) String() string {
	return uuid.UUID(i).String()
}
예제 #13
0
func (u *UID) Interface() uuid.UUID {
	return uuid.UUID(u[:])
}