func Send(client api.API, envelope *message.Envelope) error {

	// Get upload ticket
	t, err := client.GetAccountTicket(envelope.Header.From.Addr, envelope.Header.To.Addr, "")
	if err != nil {
		return err
	}
	if !t.Valid {
		return errInvalidTicket
	}

	// parallelize uploads
	g := new(errgroup.Group)
	g.Go(func() error {
		return client.UploadHeader(*t, envelope.Header)
	})
	g.Go(func() error {
		return client.UploadCatalog(*t, envelope.EncryptedCatalog)
	})
	for id, r := range envelope.BlockReaders {
		// Store locally, otherwise the anonymous go function doesn't know which "id" and "r"
		id := id
		r := r
		g.Go(func() error {
			return client.UploadBlock(*t, id, *r)
		})
	}
	for id, r := range envelope.AttachmentReaders {
		// Store locally, otherwise the anonymous go function doesn't know which "id" and "r"
		id := id
		r := r
		g.Go(func() error {
			return client.UploadBlock(*t, id, *r)
		})
	}

	// Wait until all are completed
	if err := g.Wait(); err != nil {
		_ = client.DeleteMessage(*t)
		return err
	}

	// All done, mark upload as completed
	return client.CompleteUpload(*t)
}
// Send will send a message inside envelope via routing, using addr/key
Send will send a message inside envelope via routing, using addr/key
// Send will send a message inside envelope via routing using addr / key
func Send(client api.API, envelope *message.Envelope) error {
	t, err := client.GetAccountTicket(envelope.Header.From.Addr, envelope.Header.To.Addr, "")
	if err != nil {
		return err
	}
	if !t.Valid {
		return errInvalidTicket
	}
	g := new(errgroup.Group)
	g.Go(func() error {
		return client.UploadHeader(*t, envelope.Header)
	})
	g.Go(func() error {
		return client.UploadCatalog(*t, envelope.EncryptedCatalog)
	})
	for id, r := range envelope.BlockReaders {
		id := id
		r := r
		g.Go(func() error {
			return client.UploadBlock(*t, id, *r)
		})
	}
	for id, r := range envelope.AttachmentReaders {
		id := id
		r := r
		g.Go(func() error {
			return client.UploadBlock(*t, id, *r)
		})
	}
	if err := g.Wait(); err != nil {
		_ = client.DeleteMessage(*t)
		return err
	}
	return client.CompleteUpload(*t)
}
func Send ( client api . API , envelope * message . Envelope ) error { t , err := client . GetAccountTicket ( envelope . Header . From . Addr , envelope . Header . To . Addr , " " ) if err != nil { return err } if ! t . Valid { return errInvalidTicket } g := new ( errgroup . Group ) g . Go ( func ( ) error { return client . UploadHeader ( * t , envelope . Header ) } ) g . Go ( func ( ) error { return client . UploadCatalog ( * t , envelope . EncryptedCatalog ) } ) for id , r := range envelope . BlockReaders { id := id r := r g . Go ( func ( ) error { return client . UploadBlock ( * t , id , * r ) } ) } for id , r := range envelope . AttachmentReaders { id := id r := r g . Go ( func ( ) error { return client . UploadBlock ( * t , id , * r ) } ) } if err := g . Wait ( ) ; err != nil { _ = client . DeleteMessage ( * t ) return err } return client . CompleteUpload ( * t ) }
Send will send a message inside envelope via routing, using addr/key
Send will send a message inside envelope via routing using addr / key
// Get upload ticket // parallelize uploads // Store locally, otherwise the anonymous go function doesn't know which "id" and "r" // Store locally, otherwise the anonymous go function doesn't know which "id" and "r" // Wait until all are completed // All done, mark upload as completed