// Dispatch implements core.Dispatcher.
Dispatch implements core.Dispatcher.
// Dispatch implements core . Dispatcher .
func (d *DefaultDispatcher) Dispatch(ctx context.Context, destination net.Destination) (*core.Link, error) {
	if !destination.IsValid() {
		panic("Dispatcher: Invalid destination.")
	}
	ctx = proxy.ContextWithTarget(ctx, destination)
	inbound, outbound := d.getLink(ctx)
	snifferList := proxyman.ProtocolSniffersFromContext(ctx)
	if destination.Address.Family().IsDomain() || destination.Network != net.Network_TCP || len(snifferList) == 0 {
		go d.routedDispatch(ctx, outbound, destination)
	} else {
		go func() {
			cReader := &cachedReader{
				reader: outbound.Reader.(*pipe.Reader),
			}
			outbound.Reader = cReader
			domain, err := sniffer(ctx, snifferList, cReader)
			if err == nil {
				newError("sniffed domain: ", domain).WriteToLog(session.ExportIDToError(ctx))
				destination.Address = net.ParseAddress(domain)
				ctx = proxy.ContextWithTarget(ctx, destination)
			}
			d.routedDispatch(ctx, outbound, destination)
		}()
	}
	return inbound, nil
}
func ( d * DefaultDispatcher ) Dispatch ( ctx context . Context , destination net . Destination ) ( * core . Link , error ) { if ! destination . IsValid ( ) { panic ( " " ) } ctx = proxy . ContextWithTarget ( ctx , destination ) inbound , outbound := d . getLink ( ctx ) snifferList := proxyman . ProtocolSniffersFromContext ( ctx ) if destination . Address . Family ( ) . IsDomain ( ) || destination . Network != net . Network_TCP || len ( snifferList ) == 0 { go d . routedDispatch ( ctx , outbound , destination ) } else { go func ( ) { cReader := & cachedReader { reader : outbound . Reader . ( * pipe . Reader ) , } outbound . Reader = cReader domain , err := sniffer ( ctx , snifferList , cReader ) if err == nil { newError ( " " , domain ) . WriteToLog ( session . ExportIDToError ( ctx ) ) destination . Address = net . ParseAddress ( domain ) ctx = proxy . ContextWithTarget ( ctx , destination ) } d . routedDispatch ( ctx , outbound , destination ) } ( ) } return inbound , nil }
Dispatch implements core.Dispatcher.
Dispatch implements core . Dispatcher .