2021-08-25 14:34:33 +01:00
|
|
|
/*
|
|
|
|
GoToSocial
|
2021-12-20 17:42:19 +00:00
|
|
|
Copyright (C) 2021-2022 GoToSocial Authors admin@gotosocial.org
|
2021-08-25 14:34:33 +01:00
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2021-05-17 18:06:58 +01:00
|
|
|
package transport
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"crypto"
|
2022-01-16 17:52:55 +00:00
|
|
|
"io"
|
2021-05-17 18:06:58 +01:00
|
|
|
"net/url"
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
"github.com/go-fed/httpsig"
|
2021-11-13 16:29:43 +00:00
|
|
|
"github.com/superseriousbusiness/activity/pub"
|
2021-06-27 15:52:18 +01:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
2021-05-17 18:06:58 +01:00
|
|
|
)
|
|
|
|
|
2022-03-15 14:01:19 +00:00
|
|
|
// Transport wraps the pub.Transport interface with some additional functionality for fetching remote media.
|
|
|
|
//
|
|
|
|
// Since the transport has the concept of 'shortcuts' for fetching data locally rather than remotely, it is
|
|
|
|
// not *always* the case that calling a Transport function does an http call, but it usually will for remote
|
|
|
|
// hosts or resources for which a shortcut isn't provided by the transport controller (also in this package).
|
2021-05-17 18:06:58 +01:00
|
|
|
type Transport interface {
|
|
|
|
pub.Transport
|
2022-01-23 13:41:58 +00:00
|
|
|
// DereferenceMedia fetches the given media attachment IRI, returning the reader and filesize.
|
|
|
|
DereferenceMedia(ctx context.Context, iri *url.URL) (io.ReadCloser, int, error)
|
2021-06-27 15:52:18 +01:00
|
|
|
// DereferenceInstance dereferences remote instance information, first by checking /api/v1/instance, and then by checking /.well-known/nodeinfo.
|
2021-08-25 14:34:33 +01:00
|
|
|
DereferenceInstance(ctx context.Context, iri *url.URL) (*gtsmodel.Instance, error)
|
2021-05-29 18:36:54 +01:00
|
|
|
// Finger performs a webfinger request with the given username and domain, and returns the bytes from the response body.
|
2021-08-25 14:34:33 +01:00
|
|
|
Finger(ctx context.Context, targetUsername string, targetDomains string) ([]byte, error)
|
2022-03-15 14:01:19 +00:00
|
|
|
// SigTransport returns the underlying http signature transport wrapped by the GoToSocial transport.
|
|
|
|
SigTransport() pub.Transport
|
2021-05-17 18:06:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// transport implements the Transport interface
|
|
|
|
type transport struct {
|
|
|
|
client pub.HttpClient
|
|
|
|
appAgent string
|
|
|
|
gofedAgent string
|
|
|
|
clock pub.Clock
|
|
|
|
pubKeyID string
|
|
|
|
privkey crypto.PrivateKey
|
|
|
|
sigTransport *pub.HttpSigTransport
|
|
|
|
getSigner httpsig.Signer
|
|
|
|
getSignerMu *sync.Mutex
|
2022-03-15 14:01:19 +00:00
|
|
|
|
|
|
|
// shortcuts for dereferencing things that exist on our instance without making an http call to ourself
|
|
|
|
|
|
|
|
dereferenceFollowersShortcut func(ctx context.Context, iri *url.URL) ([]byte, error)
|
|
|
|
dereferenceUserShortcut func(ctx context.Context, iri *url.URL) ([]byte, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *transport) SigTransport() pub.Transport {
|
|
|
|
return t.sigTransport
|
2021-05-17 18:06:58 +01:00
|
|
|
}
|